mirror of
https://github.com/LukeHagar/better-auth.git
synced 2025-12-08 04:19:25 +00:00
feat: custom session response (#579)
This commit is contained in:
32
demo/nextjs/lib/auth/plugins/custom-session.ts
Normal file
32
demo/nextjs/lib/auth/plugins/custom-session.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { BetterAuthPlugin } from "better-auth";
|
||||
import { createAuthEndpoint } from "better-auth/plugins";
|
||||
import { getSessionFromCtx } from "better-auth/api";
|
||||
|
||||
export const customSession = () => {
|
||||
return {
|
||||
id: "custom-session",
|
||||
endpoints: {
|
||||
getSession: createAuthEndpoint(
|
||||
"/get-session",
|
||||
{
|
||||
method: "GET",
|
||||
},
|
||||
async (ctx) => {
|
||||
const session = await getSessionFromCtx(ctx);
|
||||
if (!session) {
|
||||
return ctx.json(null);
|
||||
}
|
||||
const roles: {
|
||||
id: number;
|
||||
name: string;
|
||||
}[] = [];
|
||||
return ctx.json({
|
||||
user: session.user,
|
||||
session: session.session,
|
||||
roles,
|
||||
});
|
||||
},
|
||||
),
|
||||
},
|
||||
} satisfies BetterAuthPlugin;
|
||||
};
|
||||
Reference in New Issue
Block a user