feat(api): add protected GET /api/me and full auth round-trip test

This commit is contained in:
Bas van Rossem
2026-06-17 13:50:31 +02:00
parent 89f892ce0c
commit 04cfe0f726
3 changed files with 58 additions and 0 deletions

View File

@@ -1,10 +1,12 @@
import { Hono } from 'hono';
import { health } from './routes/health';
import { me } from './routes/me';
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));
app.route('/', me);
return app;
}

20
apps/api/src/routes/me.ts Normal file
View File

@@ -0,0 +1,20 @@
import { Hono } from 'hono';
import type { MeResponse } from '@solelog/shared';
import { auth } from '../auth';
export const me = new Hono();
me.get('/api/me', async (c) => {
const session = await auth.api.getSession({ headers: c.req.raw.headers });
if (!session) {
return c.json({ error: 'Unauthorized' }, 401);
}
const body: MeResponse = {
user: {
id: session.user.id,
email: session.user.email,
name: session.user.name,
},
};
return c.json(body);
});