Flutter › Firebase Authentication in Flutter
How does linking multiple different authentication providers to a single Firebase user account work, letting a user sign in using either Google or email and password while still resolving to the exact same underlying account?
AdvancedAnswer
Firebase Authentication supports linking several separate authentication providers, such as Google, Apple, and email and password, together to one single unified underlying user account, meaning a user who originally signed up using email and password can later choose to also link their Google account, and afterward successfully sign in using either method while Firebase correctly resolves both of those separate sign in attempts back to that exact same single underlying account, though this does require carefully and deliberately handling a genuine edge case where a user might otherwise unintentionally end up creating two separate, unlinked accounts if the linking process is not implemented carefully and correctly.
final credential = GoogleAuthProvider.credential(idToken: idToken, accessToken: accessToken);
await FirebaseAuth.instance.currentUser?.linkWithCredential(credential);Real-world example A subscription app lets an existing user who originally signed up with email and password later link their Google account as well, allowing them to conveniently sign in using either method afterward while still correctly accessing their exact same existing subscription and account data.