Ionic + Firebase, Auto Login

What is the best method to keep a user logged into an ionic 3 app with Firebase 5 after the app has been killed. Naturally, storing the username/password in the client side code (e.g. local storage, native storage) is not recommended for security reasons, returning a custom token back from firebase can be used to re-login the user if cached on the client side, but that token seems to expire very quickly with no option to adjust its expiry. (1 hour)

Try having a column in firebase that tells if user is still logged-in or not.

I have such a thing for presence detection, but in terms of auto-login of a user that kills the app, that does not seem to be very robust. There has to be some sort of authentication mechanism. The custom firebase token would make the most sense, the problem is that it expires in one hour.

Depends on how you login… as example in my Test-Application I used the standart form from the FirebaseDocs. The User stayed logged in even after a week of not using the App.

Just a little input~

What you could do is to sync the IMEI from your Phone while logging in. So after you kill the App and then restart it, it checks if this IMEI ever logged out or not.

Or use native Storage. Save the cache of the login process and maybe set a Boolean ? After you start the app, the native Storage is looking if the login cache is here if so return with a true and paste in the storaged files.

There are many possibilities on how todo it! Good luck :four_leaf_clover::grin:

The main reason this has to be done is because there seems to be an issue with Android and Firebase/Ionic disconnecting. So it is not possible to check the auth object and auto-login again.

Once the app goes into the background the firebase socket conn seems to be cut and won’t re-establish, this is being tracked as an open issue too.