dimanche 18 août 2019

Persistente with Firebase Authentication

My issue is the following: I want to keep the user logged in even if he closes and kills the flutter web app. I'm using Firebase for the authentication.

I tried setting the persistence to 'local' after the initialization of the Firebase app but this didn't work. This way it stays logged if I don't kill the app.

//This is how my initialization looks like 
...
@override
  void initState() {
    super.initState();
    if(!fb.apps.isNotEmpty){
      fb.initializeApp(
        apiKey: myApiKey,
        authDomain: myAuthDomain,
        databaseURL: myDbURL,
        storageBucket: myStorageBucket,
        projectId: myProjID,
      );
    }
  }
...

//That's when I login the user with email and password

...
 onPressed: () async {
                  var loggedUser = await auth.signInWithEmailAndPassword(email, password);
                  if(loggedUser != null){
                    Navigator.pop(context, loggedUser);
                  }else{
                    print(loggedUser);
                  }
                }
...

Do you guys have any idea?




Aucun commentaire:

Enregistrer un commentaire