mirror of
https://github.com/better-auth/better-auth.git
synced 2026-05-24 16:11:53 -05:00
feat(custom-session): add ctx on custom session callback fn
This commit is contained in:
@@ -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);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user