3

In my app, user can login as guest user. I want to authenticate the guest user with email & password, or with google. The user id should remain the same after authentication. How to do that?

1 Answer 1

4

To upgrade an anonymous account to an account with credentials, you create a new account with the sign-in method that you want to use, and then link the anonymous account and that new account together as shown in the Firebase documentation.

So in Flutter you'd use the relevant auth provider's getCredential method (e.g. Facebook or Google) and then call linkWithCredential on the anonymous user object.

Sign up to request clarification or add additional context in comments.

4 Comments

What about email-password authentication? How to get authCredential from email-password sign up?
I highly recommend browsing the documentation links I already, because it should be quite easy to find the other providers from that. Here's the way to get credentials from email+password signin: pub.dev/documentation/firebase_auth/latest/firebase_auth/…
@FrankvanPuffelen Can you please expand? Now that I've connected them, the anonymous user does not contain the authenticated user's email/displayName/photoUrl. Calling linkWithCredential also does not trigger FirebaseAuth.instance.onAuthStateChanged so there's no visible change in the UI that user has linked their account. I just want the AuthResult user returned from linkWithCredential to be the new user in the stream. I can ask a new question if you'd like.
Sounds like a new (although related) question to me, so please post as such inded. That'd also give others a chance to answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.