2

I have the following scenario: A user is authenticated anonymously with firebase auth. He then signs in into an existing account with email & password. Then, he signs out of that account again. Now, I want to recreate the anonymous account he has used before.

Is it somehow possible to store the anonymous credentials locally on the device and to use them later for signing in into the anonymous account again? I guess it would be sufficient to save the access / refresh token, but does firebase auth offer an API for that?

hendra
  • 2,531
  • 5
  • 22
  • 34

1 Answers1

1

There is no way to restore a Firebase Authentication anonymous user's UID once it's been lost. All you can do at that point is create a new anonymous account for them, but that then won't have the history of the previous account.

What you'll typically want to do is link the email+password account to the anonymous ID when the user signs in.

Then if the user ever wants to disconnect their email+password credentials, you can unlink the two accounts.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • Just for clarification, because use said "once it's been lost". I can store the UID (and other data) e.g. in Local Storage. But you mean, even if the data still exists, there is no way to restore it with the Firebase SDK? – hendra Feb 13 '20 at 15:28
  • Nope, you cannot simply restore the user from their UID. That would be quite insecure if Firebase allowed that. – Frank van Puffelen Feb 13 '20 at 15:37
  • You can try, but I'm not certain that'd work. As said in my answer, the idiomatic approach for this is to link the accounts. – Frank van Puffelen Feb 13 '20 at 17:18