skip to Main Content

I use Firebase Authentication for my app.
I can log / register correctly except when another user was log previously.

Exemple :
I am log, and I want to signout. Like this :

  final FirebaseAuth _firebaseAuth = FirebaseAuth.instance;

  signOut() async {
    await _firebaseAuth.signOut();
  }

IconButton(
                        onPressed: () {
                          signOut();
                          Navigator.of(context, rootNavigator: true)
                              .pushAndRemoveUntil(
                            MaterialPageRoute(
                              builder: (BuildContext context) {
                                return const OnBoardingPage();
                              },
                            ),
                            (_) => false,
                          );
                        },
                        icon: const Icon(Icons.logout))

So I came back to my onboarding page but I’m not fully disconnected.

I know it because I can display my email on the onboarding page (where normally no one can be connected)exemple

So, I need to restart the app, and then, I am no longer connected and user mail can’t be displayed.
I think it is something about cache but not sure.

I want to know how to fully disconnected my account of my app. and avoid persistent session after logout.

3

Answers


  1. Try

    Future<void> signOut() async {
        await _firebaseAuth.signOut();
      }
    

    and in onPressed func

    onPressed: () async {
                              await signOut();
                              Navigator.of(context, rootNavigator: true)
                                  .pushAndRemoveUntil(
                                MaterialPageRoute(
                                  builder: (BuildContext context) {
                                    return const OnBoardingPage();
                                  },
                                ),
                                (_) => false,
                              );
                            },
    
    Login or Signup to reply.
  2. check the user currently signed in or not in splash screen

    if ( FirebaseAuth.instance.currentUser != null) {
            // signed in
              return HomeScreen();
            } else {
             return LoginScreen();
            }
    

    function to sign out

     Future<void> signOut(BuildContext context) async {
    try {
     await FirebaseAuth.instance.signOut();
     Navigator.of(context).push(MaterialPageRoute(
         builder: (BuildContext context) =>  LoginScreen()));
    }catch(e){
       print("signout err:"+e.toString());
      }
    }
    

    }

    Login or Signup to reply.
  3. I’ve been having the same issue for quite some time and have tried various ways of correcting it, including the suggestions here and manually clearing all variables on sign-out. Hot reload persists the previous data but hot restart solves the issue. This issue persists in production too and is driving me nuts.

    If you’re using shared preferences it might be worth you having a look at that is the only advice I can give right now. I am about to take a deep dive into this so will come back if and when I find anything.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search