Android: For how long Firebase will remember its login?

I am using Firebase auth in my application. Currently I am using only the email and password mechanism. Below is the code I use.

private void signInUser(String email, String password)
    {
        mAuth.signInWithEmailAndPassword(email, password)
                .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        Log.d(TAG, "signInWithEmail:onComplete:" + task.isSuccessful());

                        // If sign in fails, display a message to the user. If sign in succeeds
                        // the auth state listener will be notified and logic to handle the
                        // signed in user can be handled in the listener.
                        if (!task.isSuccessful()) {
                            Log.w(TAG, "signInWithEmail:failed", task.getException());
                            Toast.makeText(MainActivity.this, "Sign In Failed",
                                    Toast.LENGTH_SHORT).show();
                        }
                        else {
                            Toast.makeText(MainActivity.this, "Sign In Success!!",
                                    Toast.LENGTH_SHORT).show();


                        }

                        // ...
                    }
                });
    }

Below is how I register a user

private void createAccount(final String email, String password)
    {
        mAuth.createUserWithEmailAndPassword(email, password)
                .addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
                    @Override
                    public void onComplete(@NonNull Task<AuthResult> task) {
                        Log.d(TAG, "createUserWithEmail:onComplete:" + task.isSuccessful());

                        // If sign in fails, display a message to the user. If sign in succeeds
                        // the auth state listener will be notified and logic to handle the
                        // signed in user can be handled in the listener.
                        if (!task.isSuccessful()) {
                            Toast.makeText(MainActivity.this,"Signup Failed",
                                    Toast.LENGTH_SHORT).show();
                            Log.e(TAG, "onComplete: Failed=" + task.getException().getMessage());
                        }
                        else
                        {
                            saveInDatabase(email);
                            Toast.makeText(MainActivity.this,"Signup Success!",
                                    Toast.LENGTH_SHORT).show();
                        }

                        // ...


                    }
                });
    }

It is true that firebase is remembering whether the user is signed in or not. That is good. But, for how long it will remember? 1 week? 1 Month? Forever? Until phone is restarted or even after phone is restarted?

Or else, do we have to set the remember time pragmatically? In that case how do we do that?

1 answer

  • answered 2018-04-14 15:07 Frank van Puffelen

    The identity of the user is remembered indefinitely (or until you sign out). But their credentials (or rather, whether their token is still valid) are re-checked every hour.