diff --git a/packages/better-auth/src/plugins/custom-session/index.ts b/packages/better-auth/src/plugins/custom-session/index.ts index cfbe72be05..1116e793f9 100644 --- a/packages/better-auth/src/plugins/custom-session/index.ts +++ b/packages/better-auth/src/plugins/custom-session/index.ts @@ -3,6 +3,7 @@ import { createAuthEndpoint, getSession } from "../../api"; import type { BetterAuthOptions, BetterAuthPlugin, + GenericEndpointContext, InferSession, InferUser, } from "../../types"; @@ -11,10 +12,13 @@ export const customSession = < Returns extends Record, O extends BetterAuthOptions = BetterAuthOptions, >( - fn: (session: { - user: InferUser; - session: InferSession; - }) => Promise, + fn: ( + session: { + user: InferUser; + session: InferSession; + }, + ctx: GenericEndpointContext, + ) => Promise, options?: O, ) => { return { @@ -81,7 +85,7 @@ export const customSession = < if (!session?.response) { return ctx.json(null); } - const fnResult = await fn(session.response as any); + const fnResult = await fn(session.response as any, ctx); session.headers.forEach((value, key) => { ctx.setHeader(key, value); });