Files
tap/app/api/auth/login/route.ts
T

13 lines
554 B
TypeScript
Raw Normal View History

import { assertSameOrigin, authFailure, jsonResponse, loginWithPassword, readJsonObject, sessionCookie } from '@/lib/server/auth';
export const runtime = 'nodejs';
export const dynamic = 'force-dynamic';
export async function POST(request: Request) {
try {
assertSameOrigin(request);
const body = await readJsonObject(request);
const { user, token } = await loginWithPassword(body.username, body.password, request);
return jsonResponse({ user }, 200, sessionCookie(token, request));
} catch (error) { return authFailure(error); }
}