lit_firebase_auth icon indicating copy to clipboard operation
lit_firebase_auth copied to clipboard

Account linking and merging

Open percula opened this issue 4 years ago • 2 comments

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.

percula avatar Dec 30 '20 17:12 percula

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

funwithflutter avatar Jan 28 '21 01:01 funwithflutter

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).

percula avatar Jan 28 '21 14:01 percula