-
Notifications
You must be signed in to change notification settings - Fork 4.1k
docs(firebase_auth): replace deprecated fetchSignInMethodsForEmail in error handling docs #18199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
9b18093
84b9e98
e49981d
25cec58
c960e9a
c838edf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
|
|
||
| <link rel="stylesheet" type="text/css" href="/styles/docs.css" /> | ||
|
|
||
|
|
@@ -51,49 +51,40 @@ 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!; | ||
|
im-manideep marked this conversation as resolved.
Outdated
|
||
| 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 | ||
| String password = '...'; | ||
|
|
||
| // Sign the user in to their account with the password | ||
| // Try signing in with email/password if applicable | ||
| try { | ||
| UserCredential userCredential = await auth.signInWithEmailAndPassword( | ||
| email: email, | ||
| password: password, | ||
| password: promptUserForPassword(), // prompt user for password | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's stick to the previous approach for the password. Instead of String password = '...'
UserCredential userCredential = await auth.signInWithEmailAndPassword(
email: email,
password: password,
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @SelaseKay I've now correctly reverted Thank you |
||
| ); | ||
|
|
||
| // 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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @im-manideep, can you rewrite this without force unwrapping? |
||
|
|
||
| // Handle other OAuth providers... | ||
| // Success! Go back to your application flow | ||
| return goToApplication(); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you revert this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@karnemanideep, you missed this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @SelaseKay! Sorry for the confusion,
I've now correctly reverted the yaml
paths back to the original format:
Project: /docs/_project.yaml
Book: /docs/_book.yaml
Both review comments are now addressed!
Please take a look when you get a chance