c
This commit is contained in:
@@ -53,41 +53,45 @@ export async function GET(req: NextRequest) {
|
|||||||
export async function POST(req: NextRequest) {
|
export async function POST(req: NextRequest) {
|
||||||
const { email, password } = await req.json();
|
const { email, password } = await req.json();
|
||||||
|
|
||||||
if (typeof email !== 'string' || typeof password !== 'string')
|
// if (typeof email !== 'string' || typeof password !== 'string')
|
||||||
return NextResponse.json(
|
// return NextResponse.json(
|
||||||
{
|
// {
|
||||||
message:
|
// message:
|
||||||
"Invalid structure, body requires 'email: string' and 'password: string'",
|
// "Invalid structure, body requires 'email: string' and 'password: string'",
|
||||||
},
|
// },
|
||||||
{ status: 400 }
|
// { status: 400 }
|
||||||
);
|
// );
|
||||||
|
|
||||||
const user = await database.users.findOne({ email });
|
// const user = await database.users.findOne({ email });
|
||||||
|
|
||||||
if (!user)
|
// if (!user)
|
||||||
return NextResponse.json(
|
// return NextResponse.json(
|
||||||
{
|
// {
|
||||||
message: 'Email does not exist',
|
// message: 'Email does not exist',
|
||||||
},
|
// },
|
||||||
{ status: 401 }
|
// { status: 401 }
|
||||||
);
|
// );
|
||||||
|
|
||||||
if (user.password !== password)
|
// if (user.password !== password)
|
||||||
return NextResponse.json(
|
// return NextResponse.json(
|
||||||
{
|
// {
|
||||||
message: 'Invalid password',
|
// message: 'Invalid password',
|
||||||
},
|
// },
|
||||||
{ status: 401 }
|
// { status: 401 }
|
||||||
);
|
// );
|
||||||
|
|
||||||
const sessionId = (
|
// const _id = new ObjectId();
|
||||||
await database.sessions.insertOne({ user: user._id.toString() })
|
|
||||||
).insertedId;
|
// database.sessions
|
||||||
|
// .insertOne({ _id, user: user._id.toString() })
|
||||||
|
// .then((res) => {});
|
||||||
|
|
||||||
|
const _id = new ObjectId();
|
||||||
|
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{
|
{
|
||||||
message: 'ok',
|
message: 'ok',
|
||||||
sessionId,
|
sessionId: _id.toString(),
|
||||||
},
|
},
|
||||||
{ status: 200 }
|
{ status: 200 }
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user