-
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
Open
im-manideep
wants to merge
6
commits into
firebase:main
Choose a base branch
from
im-manideep:docs/fix-auth-error-handling
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+35
−27
Open
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9b18093
docs(firebase_auth): replace deprecated fetchSignInMethodsForEmail in…
im-manideep 84b9e98
docs: address review feedback from SelaseKay
im-manideep e49981d
docs: revert yaml backslash escaping
im-manideep 25cec58
docs: fix yaml paths - remove backslash escaping
im-manideep c960e9a
Update errors.md
im-manideep c838edf
fix: replace force unwrapping with null checks
im-manideep File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,49 +51,45 @@ 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; | ||
| final email = e.email; | ||
| if(email == null) { | ||
| print('Email not provided in error') | ||
| return; | ||
| } | ||
| 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); | ||
| // Try signing in with Facebook if applicable | ||
| String accessToken = await triggerFacebookAuthentication(); | ||
| var facebookAuthCredential = | ||
| FacebookAuthProvider.credential(accessToken); | ||
|
|
||
| // Sign the user in with the credential | ||
| UserCredential userCredential = await auth.signInWithCredential(facebookAuthCredential); | ||
| UserCredential userCredential = | ||
| await auth.signInWithCredential(facebookAuthCredential); | ||
|
|
||
| // Link the pending credential with the existing account | ||
| await userCredential.user.linkWithCredential(pendingCredential); | ||
| // 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? |
||
|
|
||
| // Success! Go back to your application flow | ||
| return goToApplication(); | ||
| } | ||
|
|
||
| // Handle other OAuth providers... | ||
| // Success! Go back to your application flow | ||
| return goToApplication(); | ||
| } | ||
| } | ||
| ``` | ||
|
|
@@ -105,3 +101,5 @@ to be linked or your **Identity Platform** project configuration must be adjuste | |
|
|
||
| See [Phone Authentication — iOS: reCAPTCHA SDK and Identity Platform](/docs/auth/phone-auth#ios-recaptcha-sdk-and-identity-platform) for | ||
| recommended setup, the Safari flow, and a documented **GCP / Identity Toolkit** workaround with trade-offs. | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Missing indentation