feat(custom-session): add ctx on custom session callback fn

This commit is contained in:
Bereket Engida
2025-04-20 07:42:55 +03:00
parent c140af64f9
commit 57e2b8bdb2

View File

@@ -3,6 +3,7 @@ import { createAuthEndpoint, getSession } from "../../api";
import type { import type {
BetterAuthOptions, BetterAuthOptions,
BetterAuthPlugin, BetterAuthPlugin,
GenericEndpointContext,
InferSession, InferSession,
InferUser, InferUser,
} from "../../types"; } from "../../types";
@@ -11,10 +12,13 @@ export const customSession = <
Returns extends Record<string, any>, Returns extends Record<string, any>,
O extends BetterAuthOptions = BetterAuthOptions, O extends BetterAuthOptions = BetterAuthOptions,
>( >(
fn: (session: { fn: (
user: InferUser<O>; session: {
session: InferSession<O>; user: InferUser<O>;
}) => Promise<Returns>, session: InferSession<O>;
},
ctx: GenericEndpointContext,
) => Promise<Returns>,
options?: O, options?: O,
) => { ) => {
return { return {
@@ -81,7 +85,7 @@ export const customSession = <
if (!session?.response) { if (!session?.response) {
return ctx.json(null); 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) => { session.headers.forEach((value, key) => {
ctx.setHeader(key, value); ctx.setHeader(key, value);
}); });