简体   繁体   中英

Firebase Android: What happens to authenticated user after app is uninstalled?

In my android app I use firebase authentication (email/password) to authenticate users.

The app works in a way that when a user logs in I add to the database under his/her UID a flag called logged_in and set it to true , and when logged out I change the flag to false .

The structure ends like this:

Users
|
|----userID
     |
     |---name=.....
     |---logged_in = true

Problem

Now if I logged in to my app and uninstalled the app without signing out, and then reinstalled the app. I noticed that the user will be automatically signed out, and if this is the case I will end up with a user that signed out with his logged_in flag in the database set to true .

In others words I never had the chance to set the flag to false , because the user never signed out from the app.

My question:

How to overcome this problem, to always update the database when a user is automatically signed out (like my example case: where user uninstalls the app while still logged in)?

Thanks all.

in onDestroy(){ } (MainActiviry) change your logged_in == false;

Updating or deleting data https://firebase.google.com/docs/database/android/read-and-write

I think you may be misunderstanding what it means for a user to be "logged in" to your app. Logins are persistent, and they are not based on any sort of session. Firebase Authentication internally manages the token that represents their login, and it gets refreshed periodically, or after the user stops using your app for some time.

You will never be able to fully guarantee that your app can trigger some of its code when the user uninstalls, wipes their device, or simply loses their device and never comes back to your app again. Also note that your users can log in, and stay logged in, from multiple devices.

If you want to know if the user has stopped using your app for some time, you will have to record that in your database (probably by updating a field that indicates when was the last time they launched your app), and query the database (using a backend you control) to find out when that date/time becomes old enough that you are certain the user has left permanently.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM