Firebase Authentication returning specific user when app is uninstalled and Installed again

后端 未结 1 986
春和景丽
春和景丽 2021-01-06 18:00

I have an issue where I am using google sign in for my application + Firebase.

Suppose there are 3 users X,Y and Z with whom I am login in my applicatio

相关标签:
1条回答
  • 2021-01-06 18:32

    From the docs:

    When a user signs up or signs in, that user becomes the current user of the Auth instance. The Firebase Auth instance persists the user's state, so that refreshing the page (in a browser) or restarting the application doesn't lose the user's information.

    When the user signs out, the Auth instance stops keeping a reference to the User object and no longer persists its state; there is no current user. However, the user instance continues to be completely functional: if you keep a reference to it, you can still access and update the user's data.

    So to solve this, the best way is to create a button and sign out the user. That way that user won't be logged in when you restart the application.

    FirebaseAuth.getInstance().signOut();
    

    More info here: https://firebase.google.com/docs/auth/users

    Also this question related to ios (but same idea): Firebase - Deleting and reinstalling app does not un-authenticate a user

    Some other alternatives also:

    adding android:allowBackup="false" in your <application> in manifest.

    android:allowBackup

    Whether to allow the application to participate in the backup and restore infrastructure. If this attribute is set to false, no backup or restore of the application will ever be performed, even by a full-system backup that would otherwise cause all application data to be saved via adb. The default value of this attribute is true.

    Do this as a Test:

    1. Delete Cache and Data
    2. Login with User Y and Logout
    3. Login with User X and Logout
    4. Uninstall the application
    5. Install the application login with user X.

    It is important to have FirebaseAuth.getInstance().signOut(); when logging out.

    0 讨论(0)
提交回复
热议问题