Martynas Krupskis
Martynas Krupskis

Reputation: 65

How to make .getCurrentUser() return non-null?

.getCurrentUser() does not return non-null when I restart the app, therefore I stay stuck in MainActivity rather than being transferred to LogIn.class. Meaning that I am accordingly to firebase loged in constantly

I've tried attaching AuthStateListener, which does not seem to fix the problem.

@Override
protected void onStart() {
    super.onStart();

    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

    if(user == null){
        Intent intent = new Intent(MainActivity.this, LogIn.class);
        startActivity(intent);
        finish();

    } else{

    }
  }

Upvotes: 2

Views: 85

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317828

Users stay signed in until you call signOut(). So if you want getCurrentUser to return null, you must call that ahead of time.

Upvotes: 2

Related Questions