set-cookie header missing when customSession plugin is used #970

Closed
opened 2026-03-13 08:12:51 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @dennisjnnh on GitHub (Apr 3, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. create basic better-auth setup on nextjs
  2. register a user and sign-in with a low session expiresIn and updateAge
  3. notice how the set-cookie header is being returned on useSession()
  4. add this to the auth config:
    plugins: [ customSession(async data => { return data }), ],
  5. refresh the page and notice how no set-cookie header is present anymore on useSession() request

Current vs. Expected behavior

useSession() fetch should return with a set-cookie header, but it does not

What version of Better Auth are you using?

1.2.5

Provide environment information

- OS: Mac
- Browser: Safari

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

Backend

Auth config (if applicable)

import { betterAuth } from 'better-auth'
import { customSession } from 'better-auth/plugins'
import { Pool } from 'pg'

export const auth = betterAuth({
  database: new Pool({
    connectionString:
      '',
  }),
  emailAndPassword: {
    enabled: true,
  },
  session: {
    expiresIn: 20,
    updateAge: 2,
  },
  plugins: [
    customSession(async data => {
      return data
    }),
  ],
})

Additional context

No response

Originally created by @dennisjnnh on GitHub (Apr 3, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. create basic better-auth setup on nextjs 2. register a user and sign-in with a low session expiresIn and updateAge 3. notice how the set-cookie header is being returned on useSession() 4. add this to the auth config: ` plugins: [ customSession(async data => { return data }), ],` 5. refresh the page and notice how no set-cookie header is present anymore on useSession() request ### Current vs. Expected behavior useSession() fetch should return with a set-cookie header, but it does not ### What version of Better Auth are you using? 1.2.5 ### Provide environment information ```bash - OS: Mac - Browser: Safari ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from 'better-auth' import { customSession } from 'better-auth/plugins' import { Pool } from 'pg' export const auth = betterAuth({ database: new Pool({ connectionString: '', }), emailAndPassword: { enabled: true, }, session: { expiresIn: 20, updateAge: 2, }, plugins: [ customSession(async data => { return data }), ], }) ``` ### Additional context _No response_
GiteaMirror added the bug label 2026-03-13 08:12:51 -05:00
Author
Owner

@dennisjnnh commented on GitHub (Apr 3, 2025):

have also tested with the latest beta 1.2.6-beta.3, still an issue

@dennisjnnh commented on GitHub (Apr 3, 2025): have also tested with the latest beta 1.2.6-beta.3, still an issue
Author
Owner

@dennisjnnh commented on GitHub (Apr 4, 2025):

for the record, i am on nextjs
the issue is also present with nextCookies() as the last plugin in the array:

import { betterAuth } from 'better-auth'
import { nextCookies } from 'better-auth/next-js'
import { customSession } from 'better-auth/plugins'
import { Pool } from 'pg'

export const auth = betterAuth({
  database: new Pool({
    connectionString:
      'postgresql://',
  }),
  emailAndPassword: {
    enabled: true,
  },
  session: {
    expiresIn: 20,
    updateAge: 2,
  },
  plugins: [
    customSession(async data => {
      return data
    }),
    nextCookies(),
  ],
})
@dennisjnnh commented on GitHub (Apr 4, 2025): for the record, i am on nextjs the issue is also present with nextCookies() as the last plugin in the array: ``` import { betterAuth } from 'better-auth' import { nextCookies } from 'better-auth/next-js' import { customSession } from 'better-auth/plugins' import { Pool } from 'pg' export const auth = betterAuth({ database: new Pool({ connectionString: 'postgresql://', }), emailAndPassword: { enabled: true, }, session: { expiresIn: 20, updateAge: 2, }, plugins: [ customSession(async data => { return data }), nextCookies(), ], }) ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#970