Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 22 additions & 30 deletions docs/auth/errors.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Project: /docs/_project.yaml
Book: /docs/_book.yaml
Project: /docs/\_project.yaml
Book: /docs/\_book.yaml
Copy link
Copy Markdown
Contributor

@SelaseKay SelaseKay Apr 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you revert this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@karnemanideep, you missed this.


<link rel="stylesheet" type="text/css" href="/styles/docs.css" />

Expand Down Expand Up @@ -51,49 +51,41 @@ try {
} on FirebaseAuthException catch (e) {
if (e.code == 'account-exists-with-different-credential') {
// The account already exists with a different credential
String email = e.email;
AuthCredential pendingCredential = e.credential;
String email = e.email!;
AuthCredential pendingCredential = e.credential!;

// Fetch a list of what sign-in methods exist for the conflicting user
List<String> userSignInMethods = await auth.fetchSignInMethodsForEmail(email);
// Note: fetchSignInMethodsForEmail() is deprecated.
// Instead, attempt sign-in directly with known providers
// and handle the linking flow accordingly.

// If the user has several sign-in methods,
// the first method in the list will be the "recommended" method to use.
if (userSignInMethods.first == 'password') {
// Prompt the user to enter their password
// Try signing in with email/password if applicable
try {
String password = '...';

// Sign the user in to their account with the password
UserCredential userCredential = await auth.signInWithEmailAndPassword(
email: email,
password: password,
);

// Link the pending credential with the existing account
await userCredential.user.linkWithCredential(pendingCredential);

await userCredential.user!.linkWithCredential(pendingCredential);
// Success! Go back to your application flow
return goToApplication();
} on FirebaseAuthException catch (_) {
// Email/password sign-in failed, try another provider
}

// Since other providers are now external, you must now sign the user in with another
// auth provider, such as Facebook.
if (userSignInMethods.first == 'facebook.com') {
// Create a new Facebook credential
String accessToken = await triggerFacebookAuthentication();
var facebookAuthCredential = FacebookAuthProvider.credential(accessToken);

// Sign the user in with the credential
UserCredential userCredential = await auth.signInWithCredential(facebookAuthCredential);
// Try signing in with Facebook if applicable
String accessToken = await triggerFacebookAuthentication();
var facebookAuthCredential =
FacebookAuthProvider.credential(accessToken);

// Link the pending credential with the existing account
await userCredential.user.linkWithCredential(pendingCredential);
UserCredential userCredential =
await auth.signInWithCredential(facebookAuthCredential);

// Success! Go back to your application flow
return goToApplication();
}
// Link the pending credential with the existing account
await userCredential.user!.linkWithCredential(pendingCredential);

// Handle other OAuth providers...
// Success! Go back to your application flow
return goToApplication();
}
}
```
Expand Down
Loading