[PR #7217] [MERGED] fix(oauth): set account cookie on re-login when updateAccountOnSignIn is false #24054

Closed
opened 2026-04-15 22:09:07 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7217
Author: @bytaesu
Created: 1/9/2026
Status: Merged
Merged: 1/10/2026
Merged by: @himself65

Base: canaryHead: 2026-01-09/fix/account-cookie-on-relogin


📝 Commits (3)

  • bad6695 fix(oauth): set account cookie on re-login when updateAccountOnSignIn is false
  • e0f0183 test(oauth): add regression test for account cookie on re-login
  • d93e0d4 fix: use stored account for cookie to preserve token encryption

📊 Changes

2 files changed (+133 additions, -23 deletions)

View changed files

📝 packages/better-auth/src/api/routes/account.test.ts (+105 -0)
📝 packages/better-auth/src/oauth2/link-account.ts (+28 -23)

📄 Description

Context

  • Before: Even after sign-out, the account cookie remained, so re-login didn’t require resetting the cookie. This was a bug, but it was hidden.
  • In PR #6624 (a correct fix), the account cookie is now cleared on sign-out, which exposed the underlying issue.
  • Current: After re-login, when getAccessToken() was called internally, it resulted in ACCOUNT_NOT_FOUND.

Summary by cubic

Fix OAuth re-login by setting the account cookie after sign-in even when updateAccountOnSignIn is false. This prevents ACCOUNT_NOT_FOUND in getAccessToken after signing out and logging in again.

  • Bug Fixes
    • Write the account cookie on sign-in when storeAccountCookie=true, regardless of updateAccountOnSignIn.
    • Use the stored account to set the cookie to preserve token encryption.
    • Added a regression test for the Google OAuth re-login flow to ensure getAccessToken works after sign-out.

Written for commit d93e0d4db7. Summary will update on new commits.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/7217 **Author:** [@bytaesu](https://github.com/bytaesu) **Created:** 1/9/2026 **Status:** ✅ Merged **Merged:** 1/10/2026 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `2026-01-09/fix/account-cookie-on-relogin` --- ### 📝 Commits (3) - [`bad6695`](https://github.com/better-auth/better-auth/commit/bad6695de301faa1fae35c2519baeb8304fb5d71) fix(oauth): set account cookie on re-login when updateAccountOnSignIn is false - [`e0f0183`](https://github.com/better-auth/better-auth/commit/e0f01832f8d5420c692874147affcdb24dd276e9) test(oauth): add regression test for account cookie on re-login - [`d93e0d4`](https://github.com/better-auth/better-auth/commit/d93e0d4db71077266bb4fb426ed93b5a1c567154) fix: use stored account for cookie to preserve token encryption ### 📊 Changes **2 files changed** (+133 additions, -23 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/api/routes/account.test.ts` (+105 -0) 📝 `packages/better-auth/src/oauth2/link-account.ts` (+28 -23) </details> ### 📄 Description ### Context - Before: Even after sign-out, the account cookie remained, so re-login didn’t require resetting the cookie. This was a bug, but it was hidden. - In PR #6624 (a correct fix), the account cookie is now cleared on sign-out, which exposed the underlying issue. - Current: After re-login, when getAccessToken() was called internally, it resulted in ACCOUNT_NOT_FOUND. <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fix OAuth re-login by setting the account cookie after sign-in even when updateAccountOnSignIn is false. This prevents ACCOUNT_NOT_FOUND in getAccessToken after signing out and logging in again. - **Bug Fixes** - Write the account cookie on sign-in when storeAccountCookie=true, regardless of updateAccountOnSignIn. - Use the stored account to set the cookie to preserve token encryption. - Added a regression test for the Google OAuth re-login flow to ensure getAccessToken works after sign-out. <sup>Written for commit d93e0d4db71077266bb4fb426ed93b5a1c567154. Summary will update on new commits.</sup> <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-15 22:09:07 -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#24054