feat: add option to never match accounts by email address - #181
Open
heudev wants to merge 2 commits into
Open
Conversation
A verified address is matched against existing users, so a second provider sharing it joins the first account instead of registering its own. Some forums want one account per provider.
NodeBB refuses to confirm an address that another uid already holds confirmed, so with the email fallback disabled the registration threw after user.create, leaving an account with no provider association and no way to sign into it.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adds a per-strategy "Never attach this provider to an existing account that shares its email address" option.
Why
Before creating an account,
OAuth.loginlooks for an existing user with the same address:That is a reasonable default — one person, one account, several ways to sign in — but it is unconditional, and the consequence surprises people. Concretely, on a forum with GitHub and LinkedIn strategies configured, signing in with GitHub creates an account, and then signing in with LinkedIn using the same address does not create a second account: it attaches
linkedinIdto the GitHub account. The profile sync that runs on every login then overwrites the avatar and full name with the second provider's values, so the account visibly changes identity.Some deployments genuinely want one account per provider, and today there is no way to express that short of turning off
trustEmailVerified— which also disables automatic email confirmation, an unrelated concern.What changed
disableEmailFallbackcheckbox on the strategy editor, registered ineditStrategy's checkbox list so it is normalised to1/0like its siblings.OAuth.loginskips thegetUidByEmaillookup and always registers a new account.Default is off, so existing installs keep matching by email exactly as before.
Confirmation is no longer allowed to abandon the account
Turning the option on exposed a second problem.
UserEmail.confirmByUidrefuses an address that another uid already holds confirmed:Which is exactly the situation this option creates: the second provider registers a new account for an address the first account already confirmed. The throw escaped
OAuth.loginafteruser.createhad run but before${provider}Idwas written, so every attempt left behind an account nobody could sign into, and the user just saw "Bu e-posta adresi halihazırda başka biri tarafından kullanılıyor". Two logins produced two such accounts.Confirmation failure is now logged and swallowed. The account is created, the provider association is written, and the login completes — the address simply stays unconfirmed on the second account, which is the only outcome NodeBB's one-confirmed-address-per-uid rule permits.
Testing
Verified on a live NodeBB 4.14.10 forum with GitHub and LinkedIn strategies sharing one address. With the option off, the LinkedIn login attached itself to the existing GitHub account (reproducing the behaviour above). With it on, LinkedIn registered its own account and the GitHub account was left untouched.
npx eslint .is clean.