Implement comprehensive auth template system

This commit is contained in:
Aman Varshney
2025-03-21 17:44:48 +05:30
parent fbdf12fcca
commit 1ca76b23f5
22 changed files with 394 additions and 198 deletions

View File

@@ -0,0 +1,17 @@
import { betterAuth } from "better-auth";
import { prismaAdapter } from "better-auth/adapters/prisma";
import prisma from "../../prisma";
export const auth = betterAuth({
database: prismaAdapter(prisma, {
provider: "sqlite",
}),
trustedOrigins: [process.env.CORS_ORIGIN!],
emailAndPassword: { enabled: true },
advanced: {
defaultCookieAttributes: {
sameSite: "none",
secure: true,
},
},
});

View File

@@ -0,0 +1,18 @@
import type { Context as HonoContext } from "hono";
import { auth } from "./auth";
export type CreateContextOptions = {
hono: HonoContext;
};
export async function createContext({ hono }: CreateContextOptions) {
const session = await auth.api.getSession({
headers: hono.req.raw.headers,
});
return {
session,
};
}
export type Context = Awaited<ReturnType<typeof createContext>>;