feat(api): mount better-auth (email+password + bearer) on /api/auth
This commit is contained in:
@@ -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
18
apps/api/src/auth.ts
Normal 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()],
|
||||
});
|
||||
Reference in New Issue
Block a user