Repository navigation
fix(auth): link a colliding provider credential through the account that owns the address - #2564
Conversation
…hat owns the address - The account-linking recovery opens the provider that owns the address: the opt-in legacy lookup names it when it can, a lone remaining provider is opened directly, and several are offered on the method picker. - Google, Facebook and OAuth sign-ins link the pending credential before reporting success, and only to an account with the same address; a mismatch or a failed link signs back out instead of half-finishing. - Account-linking errors carry the translated recovery message instead of hard-coded English.
There was a problem hiding this comment.
Code Review
This pull request introduces a robust account-linking recovery mechanism that links a pending credential to an existing account directly inside the provider's sign-in flow. It adds the PendingAccountLink data class, the linkPendingAccountCredential helper, and updates the FirebaseAuthScreen to coordinate the recovery process, backed by comprehensive unit tests. The review feedback highlights two key improvements: using rememberSaveable instead of remember for pendingAccountLink to ensure the state survives configuration changes, and replacing referential equality (===) with structural equality (==) when comparing credentials to handle reconstructed instances.
…nk is pending The account-linking recovery prefills the account's address, but the field stays editable. Signing in elsewhere would link the credential to someone else, so the email step now refuses before signing in, as the provider flows do after.
…path - Only a sign-in through a provider the recovery offered finishes the link; any other, such as phone, drops it instead of being refused. - A mismatched account the sign-in only just created is deleted rather than left behind; a cancelled link signs back out. - The email step links the recovery's credential all or nothing, and the email-link step is held to the account's address too. - The provider credential a collision saved for a later email-link sign-in is forgotten once the recovery's link ends.
- A mismatch undone while cancelled still signs out. - An email-link sign-in counts as the Email provider, so it finishes the recovery's link instead of dropping it. - A linking error with no credential keeps the link already pending. - The credential saved for email-link sign-in is forgotten where the link resolves, not only from the screen. - No provider recovery when the collision names no address. - The email step merges the linked provider's profile again.
…ups and auto-select - The pending link is saveable, so an Activity recreated while the owner's sign-in UI is open still finishes the link. - The opt-in owner lookup shows loading, so no second sign-in can start while it runs. - Google auto-select is off while a link is pending, so a wrong pick is not handed back again.
demolaf
left a comment
There was a problem hiding this comment.
Looks good. One placement nit inline. Worth confirming that changing AccountLinkingRequiredException.message is fine for a patch release, or calling it out in the release notes.
| * Returns an [AuthRoute] rather than an [AuthRoute.Destination], because a single-provider | ||
| * configuration names a *flow*; [toKey] is what resolves it to the step to actually push. | ||
| */ | ||
| /** |
There was a problem hiding this comment.
Move PendingAccountLinkSaver above the getStartRoute KDoc. It is inserted between that KDoc and its function, so getStartRoute lost its docs.
There was a problem hiding this comment.
Moved in fd82ee1. The saver now sits above the KDoc, so getStartRoute has its docs back.
|
Thanks! The message change is called out under the PR description's behaviour changes: |
Problem
#2551 stopped the crash, but a provider sign-in that hits an existing account still can't finish. If Facebook sign-in finds an account Google created with the same email, the dialog either offers nothing (no Email provider) or sends the user to the email sign-in step, where an account with no password can't sign in. In 8.x,
WelcomeBackIdpPromptsigned the user in to the provider that owns the account and then linked the pending credential.The dialog message was also hard-coded English, so it never used the translated
accountLinkingRequiredRecoveryMessage.Change
Recovery goes to the account's owner. The
AccountLinkingRequiredExceptionrecover action now sends the user to a provider that can sign in to the existing account:legacyFetchSignInWithEmailis on and the lookup names a configured method, that one is opened. Unlike the existing different-method lookup, a password account counts here, because the email step is the way back in.Linking happens inside the provider sign-in. Google, Facebook (both through
signInAndLinkWithCredential), OAuth, the email step and email-link sign-in link the pending credential before they report success. That means the host never gets the unlinked result, and a failed link has an error path.The new
AccountLinking.ktmakes the result all or nothing:EmailAuthScreenitself is not held to this.AuthFlowScope(PendingAccountLink), shared between the screen and the provider flows, and is cleared wherever the flow ends. It's saved with the screen's state, so it survives the Activity being recreated while the owner's sign-in UI is open. A later linking error with no credential of its own (for example "Sign up" tried on the recovery's email step) keeps it.Translated messages. The six places that raised
AccountLinkingRequiredExceptionwith English text now useaccountLinkingRequiredRecoveryMessage("Account needs to be linked. Please try a different sign-in method."). That string is already translated in every locale, so no new strings are added. The mismatch message reuses the existingfui_error_user_mismatch.Behaviour changes
AccountLinkingRequiredException.messageno longer contains the email or the provider name. Hosts that read it inonSignInFailureget the translated generic copy. The email is still onexception.email.Known limitations (follow-ups)
Testing
New
AccountLinkingTest(27 tests):Successwith the linked resultNew tests in
FirebaseAuthScreenEmailRecoveryTest(8):With the link step disabled, 8 of the new tests fail. Each later fix (email-step check, owner set, new-account delete, cancel sign-out, email-step all-or-nothing, email-link check, saved-credential clear, saveable link, lookup loading, auto-select) was also disabled on its own, and its test failed each time.
./gradlew :auth:testDebugUnitTest(JDK 21): 1140 tests, 0 failures./gradlew lintAll: passMaintainer note: Fixes internal CPRN-646