Firebase kicks out current user

前端 未结 14 1811
一个人的身影
一个人的身影 2020-11-22 01:42

So I have this issue where every time I add a new user account, it kicks out the current user that is already signed in. I read the firebase api and it said that \"I

14条回答
  •  臣服心动
    2020-11-22 02:15

    I faced the same problem, and I solved it with this way:

    When the user login, I save the email and password in the shared preferences. And after creating the user, I login the user again with email and password that I have saved before.

        String currentEmail = MyApp.getSharedPreferences().getEmail();
        String currentPass = MyApp.getSharedPreferences().getPass();
    
        FirebaseAuth auth = FirebaseAuth.getInstance();
        auth.createUserWithEmailAndPassword(email, pass)
                .addOnCompleteListener(AddStudent.this, new OnCompleteListener() {
    
                    @Override
                    public void onComplete(@NonNull final Task task) {
    
                        if (task.isSuccessful()) {
                            String currentEmail = MyApp.getSharedPreferences().getEmail();
                            String currentPass = MyApp.getSharedPreferences().getPass();
    
                            //Sign in again
                            auth.signInWithEmailAndPassword(currentEmail, currentPass)
                                    .addOnCompleteListener(AddStudent.this, new OnCompleteListener() {
                                        @Override
                                        public void onComplete(@NonNull Task task) {
                                            if (!task.isSuccessful()) {
                                                Log.e("RELOGIN", "FAILED");
                                            } else {
                                                Log.e("RELOGIN", "SUCCESS");
                                            }
                                        }
                                    });
    
                            finish();
                        }
                    }
        });
    

提交回复
热议问题