fix(auth): keep the added account when adding one with 2FA #185
No reviewers
Labels
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
codefloe/forgejo-codefloe!185
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/account-switch-2fa-remember"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Adding an account through the account switcher failed silently when the new account needed 2FA and the signed-in account had a remember-me cookie.
You stayed signed in as the previous account, and the new one never appeared in the switcher.
Cause
After the password step, the sign-in flow redirects to
/user/two_factoror/user/webauthn.Those handlers, plus
/user/two_factor/scratchand/user/login/openid, callCheckAutoLogin.The remember-me cookie still belonged to the previous account, so
CheckAutoLoginsigned that account back in and redirected to/before the 2FA challenge was shown.The existing
TestAccountSwitchWith2FAmissed it because it signs in without "Remember me" and posts the passcode without loading the 2FA page.What changes
CheckAutoLogindoes nothing while an account is being added, matching what the sign-in page already did in add mode.Before, an expired session signed the browser back in as the previous account.
The navbar switcher already moves the cookie on every switch; both paths now share
moveRememberCookie.Normal (non-add) sign-ins are unchanged.
Tests
TestAccountSwitchWith2FARemembered: adds a TOTP account while remembered; the 2FA, scratch and WebAuthn pages now render instead of answering303 → /, and the added account ends up active with the previous one in the switcher.TestAccountSwitchAddMovesRememberCookie: after adding an account without "Remember me", the remember-me cookie alone signs in the added account.TestAccountSwitch*,TestSelectAccount*,TestLTA*,TestSignin*,TestTOTP*,TestTwoFactor*,TestWebAuthn*,TestUserLogin*,TestOAuth2*,TestAuthorize*pass on sqlite (48 tests).204716f8d94ccd45a56e