getCookieCache returns null #1322

Closed
opened 2026-03-13 08:32:42 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @juliocanares on GitHub (Jun 7, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Enable cookieCache
session: {
    cookieCache: {
      enabled: true,
      maxAge: 5 * 60,
    }
}
  1. Try to access the cookie session value from the cache using getCookieCache convenient as the getSessionCookie.
  2. getCookieCache returns null because it tries to parse a base64 string instead of decoding first.

Current vs. Expected behavior

Should return the session data instead of null

What version of Better Auth are you using?

1.2.8

Provide environment information

Mac OS

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

Backend

Auth config (if applicable)


Additional context

I made this change on the cookies file to actually parse it like in the getSession endpoint and it works.

// packages/better-auth/src/cookies/index.ts:312
if (sessionData) {
    return safeJSONParse<Session>(binary.decode(base64.decode(sessionData)));
}
Originally created by @juliocanares on GitHub (Jun 7, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Enable cookieCache ```ts session: { cookieCache: { enabled: true, maxAge: 5 * 60, } } ``` 2. Try to access the cookie session value from the cache using `getCookieCache` convenient as the `getSessionCookie`. 3. getCookieCache returns null because it tries to parse a base64 string instead of decoding first. ### Current vs. Expected behavior Should return the session data instead of null ### What version of Better Auth are you using? 1.2.8 ### Provide environment information ```bash Mac OS ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript ``` ### Additional context I made this change on the cookies file to actually parse it like in the getSession endpoint and it works. ```ts // packages/better-auth/src/cookies/index.ts:312 if (sessionData) { return safeJSONParse<Session>(binary.decode(base64.decode(sessionData))); } ```
Author
Owner

@Kinfe123 commented on GitHub (Jun 7, 2025):

it is fixed. closing it now.

@Kinfe123 commented on GitHub (Jun 7, 2025): it is fixed. closing it now.
Author
Owner

@juliocanares commented on GitHub (Jun 8, 2025):

@Kinfe123 I see the pr was closed with unmerged commits https://github.com/better-auth/better-auth/pull/2945 👀

@juliocanares commented on GitHub (Jun 8, 2025): @Kinfe123 I see the pr was closed with unmerged commits https://github.com/better-auth/better-auth/pull/2945 👀
Author
Owner

@Bekacru commented on GitHub (Jun 8, 2025):

@juliocanares 5eb3c03176

@Bekacru commented on GitHub (Jun 8, 2025): @juliocanares https://github.com/better-auth/better-auth/commit/5eb3c0317632bc29496b1f45e88bb6146932737a
Author
Owner

@juliocanares commented on GitHub (Jun 8, 2025):

TY @Bekacru

@juliocanares commented on GitHub (Jun 8, 2025): TY @Bekacru
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1322