Skip to content

Fix: always pass tokenExpiration for frontend session cookies#154

Open
smakman wants to merge 1 commit intoauthsmith:mainfrom
smakman:fix/frontend-cookie-expiration
Open

Fix: always pass tokenExpiration for frontend session cookies#154
smakman wants to merge 1 commit intoauthsmith:mainfrom
smakman:fix/frontend-cookie-expiration

Conversation

@smakman
Copy link

@smakman smakman commented Mar 10, 2026

Summary

For non-admin (frontend) logins, useAdmin is false, so the ternary expression:

useAdmin ? collectionConfig.auth.tokenExpiration : undefined

passes undefined to createSessionCookies(), which then falls back to the hardcoded 7200s (2 hour) default. This means the collection's configured auth.tokenExpiration is silently ignored for all frontend logins — only admin logins respect it.

This affects three flows:

  • OAuth authentication (src/core/protocols/oauth/oauth_authentication.ts)
  • Password signin (src/core/protocols/password.tsPasswordSignin)
  • Password signup (src/core/protocols/password.tsPasswordSignup)

Fix

Remove the useAdmin conditional and always pass collectionConfig.auth.tokenExpiration to createSessionCookies(), so both admin and frontend session cookies use the collection's configured token expiration.

Before:

useAdmin ? collectionConfig.auth.tokenExpiration : undefined

After:

collectionConfig.auth.tokenExpiration

Test plan

  • Configure a collection with a custom auth.tokenExpiration (e.g. 86400 for 24h)
  • Sign in via the frontend (non-admin) using password auth and verify the session cookie expiration matches the configured value instead of defaulting to 7200s
  • Sign in via the frontend using OAuth and verify the same
  • Sign up with allowAutoSignin: true and verify the session cookie expiration is correct
  • Verify admin login still works correctly with the configured expiration

🤖 Generated with Claude Code

For non-admin (frontend) logins, `useAdmin` is false, so the ternary `useAdmin ? collectionConfig.auth.tokenExpiration : undefined` was passing `undefined` to `createSessionCookies()`, which falls back to the hardcoded 7200s default. This means the collection's configured `auth.tokenExpiration` was being ignored for all frontend logins. Remove the `useAdmin` conditional and always pass `collectionConfig.auth.tokenExpiration` in OAuth authentication, password signin, and password signup flows. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant