Merging of Providers

in flutter •  3 years ago  (edited)

Hello developers 👏

It's fishy when it comes to merging between the account merging between Google and Facebook. <{❤️}>
What's the issue? <{❤️}>

  1. When signing in with Google, generally all the applications directly allow you to sign in with your account.
  2. ex: When you sign-in with an email ex: [email protected]
  3. Let's suppose you have the same email address you use for Facebook, when you try signing in with Facebook, it fails with an exception that "ERROR_ACCOUNT_EXISTS_WITH_DIFFERENT_CREDENTIAL", this is because the primary email is always Google for any platform you consider.
  4. In this case, the dart platform provides an efficient tool called LinkWithCredientials

Here is the dart code for Google authentication <{❤️}>
Merging-of-Providers-DEV-Community-__.png

Here is the dart code for Facebook authentication <{❤️}>

Merging-of-Providers-DEV-Community-__ (1).png

Now the above code throws an exception if the account has already been signed in with Google. To overcome this error use the try-catch block and embed the code inside it. Now when the exception is caught by try-catch use the code to check if the exception is the same as I have mentioned above, and use the proper creds.

Merging-of-Providers-DEV-Community-__ (2).png

Now this will link the user directly to Google(or any other providers of your choice).

This is a simple solution. Though the documentation of firebase says it all, practically they have not shown it for the dart.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  
Loading...