twoFactor (2FA) plugin doesn't respect "Remember me" login option (not mistaken with 2FA trustDevice) #739

Closed
opened 2026-03-13 08:02:14 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @theinfinit on GitHub (Feb 24, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Launch NextJS demo.
  2. Log-in (open DevTools to confirm that session cookie is present without 2FA)
  3. Enable 2FA.
  4. Log-out (All cookies should be gone now).
  5. Log-in again providing 2FA code. Make sure to NOT check "Remember me" (dont_remember cookie will not be present)
  6. 7 day cookie will be added instead of session cookie.
  7. Log-out (All cookies should be gone now, except better-auth.two_factor, which is not removed on sign-out, but probably should).

Current vs. Expected behavior

Following the steps from the previous section, I expected that "Remember me" option will be respected, even if user enabled 2FA for their account. I observed, instead, that after user enables 2FA for their account, better-auth is adding 7 day cookie instead of session cookie.

Additionally I observed that better-auth.two_factor cookie is not removed on sign-out. When I tried to go to /two-factor/ page without login step, I was able to successfully authenticate in "one-step" verification and get access to dashboard.

Both issues are considered with untrusted devices used by non-technical user. If someone is using untrusted browser, without using private window, forgets to sign out, they should rest assured that their account is secure, if they haven't selected "Remember me" option.

Image

What version of Better Auth are you using?

Tested against main branch v1.1.20

Provide environment information

OS: Windows 11
Browser: Vivaldi 7.1.3570.54 (Stable channel) (64-bit) (chromium)

Which area(s) are affected? (Select all that apply)

Client, Backend

Auth config (if applicable)

Config as in demo/nextjs, but with local better-sqlite DB.

Additional context

I tested my reproduction against main branch v1.1.20.

Originally created by @theinfinit on GitHub (Feb 24, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Launch NextJS demo. 2. Log-in (open DevTools to confirm that `session` cookie is present without 2FA) 3. Enable 2FA. 4. Log-out (All cookies should be gone now). 5. Log-in again providing 2FA code. Make sure to NOT check "Remember me" (dont_remember cookie will not be present) 6. 7 day cookie will be added instead of session cookie. 7. Log-out (All cookies should be gone now, except `better-auth.two_factor`, which is not removed on sign-out, but probably should). ### Current vs. Expected behavior Following the steps from the previous section, I expected that "Remember me" option will be respected, even if user enabled 2FA for their account. I observed, instead, that after user enables 2FA for their account, better-auth is adding 7 day cookie instead of `session` cookie. Additionally I observed that `better-auth.two_factor` cookie is not removed on sign-out. When I tried to go to `/two-factor/` page without login step, I was able to successfully authenticate in "one-step" verification and get access to dashboard. Both issues are considered with untrusted devices used by non-technical user. If someone is using untrusted browser, without using private window, forgets to sign out, they should rest assured that their account is secure, if they haven't selected "Remember me" option. ![Image](https://github.com/user-attachments/assets/a7456fbf-4608-43b5-8f6c-ec4da359405a) ### What version of Better Auth are you using? Tested against main branch v1.1.20 ### Provide environment information ```bash OS: Windows 11 Browser: Vivaldi 7.1.3570.54 (Stable channel) (64-bit) (chromium) ``` ### Which area(s) are affected? (Select all that apply) Client, Backend ### Auth config (if applicable) ```typescript Config as in demo/nextjs, but with local better-sqlite DB. ``` ### Additional context I tested my reproduction against main branch v1.1.20.
GiteaMirror added the bug label 2026-03-13 08:02:14 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#739