From 0aa6dff678afeabdaba5bcbecc10e5b2413a6b77 Mon Sep 17 00:00:00 2001 From: Alex Yang Date: Tue, 28 Oct 2025 17:11:52 -0700 Subject: [PATCH] feat: session store chunking (#5645) Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../better-auth/src/api/routes/session.ts | 29 +- .../better-auth/src/cookies/cookies.test.ts | 312 ++++++++++++++++-- packages/better-auth/src/cookies/index.ts | 66 +++- .../better-auth/src/cookies/session-store.ts | 288 ++++++++++++++++ 4 files changed, 638 insertions(+), 57 deletions(-) create mode 100644 packages/better-auth/src/cookies/session-store.ts diff --git a/packages/better-auth/src/api/routes/session.ts b/packages/better-auth/src/api/routes/session.ts index 294fd3ee76..3b2b5e26f6 100644 --- a/packages/better-auth/src/api/routes/session.ts +++ b/packages/better-auth/src/api/routes/session.ts @@ -14,37 +14,17 @@ import { APIError } from "better-call"; import * as z from "zod"; import { deleteSessionCookie, + getChunkedCookie, setCookieCache, setSessionCookie, } from "../../cookies"; -import { symmetricDecodeJWT } from "../../crypto/jwt"; +import { getSessionQuerySchema } from "../../cookies/session-store"; +import { symmetricDecodeJWT } from "../../crypto"; import type { InferSession, InferUser, Session, User } from "../../types"; import type { Prettify } from "../../types/helper"; import { getDate } from "../../utils/date"; import { safeJSONParse } from "../../utils/json"; -export const getSessionQuerySchema = z.optional( - z.object({ - /** - * If cookie cache is enabled, it will disable the cache - * and fetch the session from the database - */ - disableCookieCache: z.coerce - .boolean() - .meta({ - description: "Disable cookie cache and fetch session from database", - }) - .optional(), - disableRefresh: z.coerce - .boolean() - .meta({ - description: - "Disable session refresh. Useful for checking session status, without updating the session", - }) - .optional(), - }), -); - export const getSession =