more mobile compatible

This commit is contained in:
2025-02-17 21:17:49 +01:00
parent 9684a18046
commit 308bd35ce8
13 changed files with 656 additions and 54 deletions
+44
View File
@@ -46,3 +46,47 @@ export async function GET(req: NextRequest) {
{ status: 200 }
);
}
// Account login
// Email exists
// Password is valid
export async function POST(req: NextRequest) {
const { email, password } = await req.json();
if (typeof email !== 'string' || typeof password !== 'string')
return NextResponse.json(
{
message:
"Invalid structure, body requires 'email: string' and 'password: string'",
},
{ status: 400 }
);
const user = await database.users.findOne({ email });
if (!user)
return NextResponse.json(
{
message: 'Invalid email',
},
{ status: 401 }
);
if (user.password !== password)
return NextResponse.json(
{
message: 'Invalid password',
},
{ status: 401 }
);
const sessionId = (await database.sessions.insertOne({ email })).insertedId;
return NextResponse.json(
{
message: 'ok',
sessionId,
},
{ status: 200 }
);
}