implement better-auth auth with postgres and route protection

This commit is contained in:
2026-02-24 13:32:43 -05:00
parent fd168f607c
commit 52a4ab38d3
31 changed files with 1202 additions and 89 deletions

View File

@@ -1,9 +1,15 @@
import type { TaskStatus } from '@/lib/types';
import { requireAuthenticatedSession } from '@/lib/server/auth-session';
import { listRecentTasks } from '@/lib/server/tasks';
const ALLOWED_STATUSES: TaskStatus[] = ['queued', 'running', 'completed', 'failed'];
export async function GET(request: Request) {
const { session, response } = await requireAuthenticatedSession();
if (response) {
return response;
}
const url = new URL(request.url);
const limitValue = Number(url.searchParams.get('limit') ?? 20);
const limit = Number.isFinite(limitValue)
@@ -15,6 +21,6 @@ export async function GET(request: Request) {
return ALLOWED_STATUSES.includes(status as TaskStatus);
});
const tasks = await listRecentTasks(limit, statuses.length > 0 ? statuses : undefined);
const tasks = await listRecentTasks(session.user.id, limit, statuses.length > 0 ? statuses : undefined);
return Response.json({ tasks });
}