Search code examples
androidfirebasefirebase-authenticationgoogle-smartlockpasswords

How can I choose default credential if multiple in google smart lock Firebase?


I'm creating an app using Firebase with a Friebase UI library for authentication wrapper. Firebase UI uses Google Smart Lock to detect previously logged user and automatically log in when app is opened again. The problem appears when I add another google user to the app. Then every time it shows me a dialog with all google users and I have to select one of them which adds unnecessary step.

Multiple credentials screen

Logging in Diagram

Is there any way to make Firebase Auth store the selected user as default and then automatically log in with him every time?

Thanks


Solution

  • It turns out Google is smarter than I thought. The default credential gets chosen automatically anyway. The mistake was on my side:

     auth = FirebaseAuth.getInstance();
        FirebaseUser fUser = auth.getCurrentUser();
        if (fUser != null) { //this line triggers multiple users dialog
            startActivity(ActivityAddEventPopup.createIntent(this, null));
            finish();
    
        } 
    
    signIn();
    

    My signIn(); was always called without the else block. Which means it always triggered the FULL authentication procedure from the start (look at the diagram). Solution was to put signIn in an else block so that it won't get called all the time. Firebase Auth will retrieve the last chosen user and log in with him.