feat(api): mount better-auth (email+password + bearer) on /api/auth

This commit is contained in:
Bas van Rossem
2026-06-17 13:47:20 +02:00
parent e8aa2c67e8
commit 89f892ce0c
3 changed files with 48 additions and 0 deletions

View File

@@ -1,8 +1,10 @@
import { Hono } from 'hono';
import { health } from './routes/health';
import { auth } from './auth';
export function createApp(): Hono {
const app = new Hono();
app.route('/', health);
app.on(['POST', 'GET'], '/api/auth/*', (c) => auth.handler(c.req.raw));
return app;
}

18
apps/api/src/auth.ts Normal file
View File

@@ -0,0 +1,18 @@
import { betterAuth } from 'better-auth';
import { drizzleAdapter } from 'better-auth/adapters/drizzle';
import { bearer } from 'better-auth/plugins';
import { db } from './db/client';
import * as schema from './db/schema';
import { env } from './env';
export const auth = betterAuth({
secret: env.BETTER_AUTH_SECRET,
baseURL: env.BETTER_AUTH_URL,
trustedOrigins: [env.BETTER_AUTH_URL, 'http://localhost:3000'],
database: drizzleAdapter(db, { provider: 'sqlite', schema }),
emailAndPassword: {
enabled: true,
requireEmailVerification: false,
},
plugins: [bearer()],
});