24 lines
746 B
TypeScript
24 lines
746 B
TypeScript
import { betterAuth } from "better-auth";
|
|
import { drizzleAdapter } from "better-auth/adapters/drizzle";
|
|
import { anonymous } from "better-auth/plugins/anonymous";
|
|
import type { Db } from "./db/client";
|
|
import * as authSchema from "./db/auth-schema";
|
|
|
|
export interface AuthSettings {
|
|
secret: string;
|
|
baseUrl: string;
|
|
}
|
|
|
|
/** Better Auth with guest (anonymous) sign-in, storing users and sessions in Postgres. */
|
|
export function createAuth(db: Db, settings: AuthSettings) {
|
|
return betterAuth({
|
|
database: drizzleAdapter(db, { provider: "pg", schema: authSchema }),
|
|
secret: settings.secret,
|
|
baseURL: settings.baseUrl,
|
|
basePath: "/api/auth",
|
|
plugins: [anonymous()],
|
|
});
|
|
}
|
|
|
|
export type Auth = ReturnType<typeof createAuth>;
|