14 lines
554 B
TypeScript
14 lines
554 B
TypeScript
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); }
|
|
}
|