diff --git a/src/app/api/login.ts b/src/app/api/login.ts index b7b87a0..6227142 100644 --- a/src/app/api/login.ts +++ b/src/app/api/login.ts @@ -2,14 +2,23 @@ import prisma from "app/lib/db"; import bcrypt from 'bcrypt'; export type User = { - id: number, + id?: number, email: string, password: string, } export default async function authenticate(clientUser: User) { const dbUser: User = await prisma.user.findFirst({ where: { email: clientUser.email } }) - if (!dbUser) return null - - + if (!dbUser) return "user doesn't exist" + const passwordMatches = await + bcrypt.compare(clientUser.password, dbUser.password) + if (!passwordMatches) return "password doesn't match" + return "password matches!" } + +let res = await authenticate({ email: "nobody", password: "nothing" }) +console.log("nonexistent user: " + res) +res = await authenticate({ email: "demo@demo.demo", password: "nothing" }) +console.log("existent user, bad password: " + res) +res = await authenticate({ email: "demo@demo.demo", password: "password" }) +console.log("existent user, good password: " + res)