Hello developers 👏
It's fishy when it comes to merging between the account merging between Google and Facebook. <{❤️}>
What's the issue? <{❤️}>
- When signing in with Google, generally all the applications directly allow you to sign in with your account.
- ex: When you sign-in with an email ex: [email protected]
- 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.
- In this case, the dart platform provides an efficient tool called LinkWithCredientials
Here is the dart code for Google authentication <{❤️}>
Here is the dart code for Facebook authentication <{❤️}>
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.
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.