Additional field with returned set to false gets included in the cached session data cookie on signin #1012

Closed
opened 2026-03-13 08:17:41 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @sakshamarora10 on GitHub (Apr 8, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Create an additional field with returned set to false
  2. Enable cookie caching
  3. Sign in

Current vs. Expected behavior

Expected behaviour

Since returned is set to false for the additional field, it should not be included in the session response or in the session data stored in the cached cookie.

Current Behaviour

The field is stored in the cached cookie data

Image

What version of Better Auth are you using?

1.2.5

Provide environment information

- OS: MACOS 15.3.1
- Browser: Chrome

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

Backend

Auth config (if applicable)

import { betterAuth } from 'better-auth';

export const auth = betterAuth({
  user: {
    additionalFields: {
      riskLevel: {
        type: 'string',
        required: false,
        input: false,
        returned: false,
      },
    },
  },

  session: {
    cookieCache: {
      enabled: true,
      maxAge: 5 * 60,
    },
  },

  //...
});

Additional context

No response

Originally created by @sakshamarora10 on GitHub (Apr 8, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Create an additional field with returned set to false 2. Enable cookie caching 3. Sign in ### Current vs. Expected behavior ### Expected behaviour Since returned is set to false for the additional field, it should not be included in the session response or in the session data stored in the cached cookie. ### Current Behaviour The field is stored in the cached cookie data ![Image](https://github.com/user-attachments/assets/25265151-69bb-472a-b737-4bf1b5675e5f) ### What version of Better Auth are you using? 1.2.5 ### Provide environment information ```bash - OS: MACOS 15.3.1 - Browser: Chrome ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from 'better-auth'; export const auth = betterAuth({ user: { additionalFields: { riskLevel: { type: 'string', required: false, input: false, returned: false, }, }, }, session: { cookieCache: { enabled: true, maxAge: 5 * 60, }, }, //... }); ``` ### Additional context _No response_
Author
Owner

@sakshamarora10 commented on GitHub (Apr 9, 2025):

Interestingly, all the subsequent data cookies that are generated through authClient.useSession or auth.api.getSession do not have the said field, confirming that there's a flaw in sign in implementation

@sakshamarora10 commented on GitHub (Apr 9, 2025): Interestingly, all the subsequent data cookies that are generated through `authClient.useSession ` or `auth.api.getSession` do not have the said field, confirming that there's a flaw in sign in implementation
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1012