[PR #9103] feat: warn when cookie integration plugins are not last in plugins[] #16683

Open
opened 2026-04-13 10:38:37 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/9103
Author: @h30s
Created: 4/10/2026
Status: 🔄 Open

Base: main ← Head: feat/cookie-plugin-order-guardrail


📝 Commits (3)

  • f3b0c9e feat: warn when cookie integration plugins are not last in plugins[]
  • 867fa9c chore: fix CI issues (lint formatting, missing changeset)
  • 432ca87 chore: fix cspell error

📊 Changes

3 files changed (+128 additions, -0 deletions)

View changed files

➕ .changeset/cookie-plugin-guardrail.md (+5 -0)
📝 packages/better-auth/src/context/create-context.test.ts (+91 -0)
📝 packages/better-auth/src/context/create-context.ts (+32 -0)

📄 Description

Problem: Cookie integration plugins (nextCookies, tanstackStartCookies, sveltekitCookies) must be last in plugins[]. If they're not, cookies from subsequent plugins are silently dropped — causing missing sessions, broken 2FA, and redirect loops with no error shown.

Fix: Added a logger.warn() in createAuthContext that detects when a cookie integration plugin is not in the final position and prints a clear message with the fix.

Closes #8911


Summary by cubic

Add a guardrail that warns when cookie integration plugins aren’t last in plugins[]. This prevents silent cookie drops that cause missing sessions, broken 2FA, or redirect loops.

  • Bug Fixes
    • In createAuthContext, log a logger.warn if any of next-cookies, tanstack-start-cookies, tanstack-start-cookies-solid, or sveltekit-cookies appear before the last plugin. The warning lists all misplaced IDs and explains the fix.
    • Added tests for misordered vs. correct order, single-plugin setups, and cases where one or multiple known cookie plugins are misplaced.

Written for commit 432ca87eeb. 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/9103 **Author:** [@h30s](https://github.com/h30s) **Created:** 4/10/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `feat/cookie-plugin-order-guardrail` --- ### 📝 Commits (3) - [`f3b0c9e`](https://github.com/better-auth/better-auth/commit/f3b0c9e2fe496682ddb648b6d8d39e964bd56e16) feat: warn when cookie integration plugins are not last in plugins[] - [`867fa9c`](https://github.com/better-auth/better-auth/commit/867fa9c5a7cedcdcc842a3b0406f1c6cde781f9c) chore: fix CI issues (lint formatting, missing changeset) - [`432ca87`](https://github.com/better-auth/better-auth/commit/432ca87eebbfa87608015bb60f6798b747d11fce) chore: fix cspell error ### 📊 Changes **3 files changed** (+128 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `.changeset/cookie-plugin-guardrail.md` (+5 -0) 📝 `packages/better-auth/src/context/create-context.test.ts` (+91 -0) 📝 `packages/better-auth/src/context/create-context.ts` (+32 -0) </details> ### 📄 Description Problem: Cookie integration plugins (nextCookies, tanstackStartCookies, sveltekitCookies) must be last in plugins[]. If they're not, cookies from subsequent plugins are silently dropped — causing missing sessions, broken 2FA, and redirect loops with no error shown. Fix: Added a logger.warn() in createAuthContext that detects when a cookie integration plugin is not in the final position and prints a clear message with the fix. Closes #8911 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Add a guardrail that warns when cookie integration plugins aren’t last in `plugins[]`. This prevents silent cookie drops that cause missing sessions, broken 2FA, or redirect loops. - **Bug Fixes** - In `createAuthContext`, log a `logger.warn` if any of `next-cookies`, `tanstack-start-cookies`, `tanstack-start-cookies-solid`, or `sveltekit-cookies` appear before the last plugin. The warning lists all misplaced IDs and explains the fix. - Added tests for misordered vs. correct order, single-plugin setups, and cases where one or multiple known cookie plugins are misplaced. <sup>Written for commit 432ca87eebbfa87608015bb60f6798b747d11fce. 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-13 10:38:37 -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#16683