import type { BetterAuthPlugin } from 'better-auth';
import { createAuthEndpoint } from 'better-auth/api';
import { z } from 'zod';
const setSchool = createAuthEndpoint(
'/schools/set-school',
{
method: 'POST',
body: z.object({ schoolId: z.string(), name: z.string() }),
},
async (ctx) => {
const { schoolId: id, name } = ctx.body;
await ctx.setSignedCookie(
'school',
JSON.stringify({ id, name }),
ctx.context.secret
);
return ctx.json({ success: true });
}
);
export const schools = () => {
return {
id: 'schools',
endpoints: {
setSchool,
},
} satisfies BetterAuthPlugin;
};
import type { BetterAuthPlugin } from 'better-auth';
import { createAuthEndpoint } from 'better-auth/api';
import { z } from 'zod';
const setSchool = createAuthEndpoint(
'/schools/set-school',
{
method: 'POST',
body: z.object({ schoolId: z.string(), name: z.string() }),
},
async (ctx) => {
const { schoolId: id, name } = ctx.body;
await ctx.setSignedCookie(
'school',
JSON.stringify({ id, name }),
ctx.context.secret
);
return ctx.json({ success: true });
}
);
export const schools = () => {
return {
id: 'schools',
endpoints: {
setSchool,
},
} satisfies BetterAuthPlugin;
};