diff --git a/.gitignore b/.gitignore index 5ef6a52..2448ddc 100644 --- a/.gitignore +++ b/.gitignore @@ -39,3 +39,6 @@ yarn-error.log* # typescript *.tsbuildinfo next-env.d.ts + +# Local Netlify folder +.netlify diff --git a/src/app/api/session/route.ts b/src/app/api/session/route.ts index b70ed6d..3582a17 100644 --- a/src/app/api/session/route.ts +++ b/src/app/api/session/route.ts @@ -53,41 +53,39 @@ export async function GET(req: NextRequest) { 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 } - // ); + 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 }); + const user = await database.users.findOne({ email }); - // if (!user) - // return NextResponse.json( - // { - // message: 'Email does not exist', - // }, - // { status: 401 } - // ); + if (!user) + return NextResponse.json( + { + message: 'Email does not exist', + }, + { status: 401 } + ); - // if (user.password !== password) - // return NextResponse.json( - // { - // message: 'Invalid password', - // }, - // { status: 401 } - // ); - - // const _id = new ObjectId(); - - // database.sessions - // .insertOne({ _id, user: user._id.toString() }) - // .then((res) => {}); + if (user.password !== password) + return NextResponse.json( + { + message: 'Invalid password', + }, + { status: 401 } + ); const _id = new ObjectId(); + database.sessions + .insertOne({ _id, user: user._id.toString() }) + .then((res) => {}); + return NextResponse.json( { message: 'ok',