Skip to content

Account linking and merging #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

percula
Copy link

@percula percula commented Dec 30, 2020

This PR resolves #16

If a user is already logged in, lit tries to link the credential to their account. Thus, anonymous users can upgrade to a non-anonymous account. If that credential is already associated with an account, lit will call the LinkMergeConflictCallback (if non-null) to resolve the merge conflict. The developer is responsible for merging data (from Firestore, Realtime Database, etc) within that callback, using the credentialForLinking to sign-in as the new user and migrate the data.

Note, there is a bug with the FirebaseAuthOAuth plugin where no exception is thrown when there is already an existing account. I've created an issue in that repo to address it. Unfortunately, that means that account merging only works for sign in methods that use FirebaseAuthFacade.signInWithCredential(). Once that issue is resolved, we can simply catch the exception and return Auth.failure(AuthFailure.linkMergeConflict(e.credential)). I'm hoping the credential will be in the exception, but if not I'm not sure how to handle that.

@funwithflutter
Copy link
Owner

Thanks for the pull request! As I understand this is still only usable for signInWithCredentials right?

@percula
Copy link
Author

percula commented Jan 28, 2021

Correct, it's only usable with signInWithCredentials. Unfortunately, the issue I mentioned with FirebaseAuthOAuth is not simple to solve. In my testing, both Twitter and Apple did not throw an exception to indicate that there is already an existing account. And the package returns the User already signed-in, not the credentials to sign in, so it's impossible to do linking and merging outside the package. I ended up implementing my own auth solution so that I can appropriately link and merge accounts, utilizing the individual libraries google_sign_in, flutter_facebook_auth, and sign_in_with_apple (I'm dropping support for Twitter sign in).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Account linking
2 participants