Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Persist user on App Reinstall with Firebase

When a user deletes and reinstalls my app, I want their anonymous user account to persist. My iOS app is working as expected, but Android is not. I create anonymous users like so

if (auth.getCurrentUser() == null) {
    auth.signInAnonymously().addOnCompleteListener(task -> {});
}

When I delete the app and reinstall, auth.getCurrentUser() is null and I have to re-authenticate.

My AndroidManifest.xml contains android:allowBackup="true"

like image 269
MCR Avatar asked Sep 07 '17 14:09

MCR


1 Answers

It is null becase Firebase Anonymous Authentication accounts does not persist across application uninstalls. If you uninstall the application, everything that was saved locally will be deleted, including the anonymous auth token that identifies that account. There is no way to reclaim that token for the user. You can use Firebase Anonymous Authentication to create and use temporary accounts to authenticate users in your application.

These temporary anonymous accounts can be used to allow users who haven't yet signed up to your app. If such an anonymous user decides later to sign up to your application, you can link their sign-in credentials to the anonymous account. What should you do, you should encourage your users to fully log in with a supported account provider so that they can log in from all their devices without worry of losing their data.

like image 156
Alex Mamo Avatar answered Oct 02 '22 20:10

Alex Mamo