owltide/server/api/auth/login.post.ts

19 lines
428 B
TypeScript
Raw Normal View History

import { readAccounts } from "~/server/database";
export default defineEventHandler(async (event) => {
const { name } = await readBody(event);
if (!name) {
return new Response(undefined, { status: 400 })
}
const accounts = await readAccounts();
const account = accounts.find(a => a.name === name);
if (!account) {
return new Response(undefined, { status: 403 })
}
await setAccountSession(event, account.id);
})