({
email,
password,
}: {
email: string;
password: string;
})
| 51 | omit<O>(user, ['password', 'iat']); |
| 52 | |
| 53 | export function authenticate({ |
| 54 | email, |
| 55 | password, |
| 56 | }: { |
| 57 | email: string; |
| 58 | password: string; |
| 59 | }) { |
| 60 | const user = db.user.findFirst({ |
| 61 | where: { |
| 62 | email: { |
| 63 | equals: email, |
| 64 | }, |
| 65 | }, |
| 66 | }); |
| 67 | |
| 68 | if (user?.password === hash(password)) { |
| 69 | const sanitizedUser = sanitizeUser(user); |
| 70 | const encodedToken = encode(sanitizedUser); |
| 71 | return { user: sanitizedUser, jwt: encodedToken }; |
| 72 | } |
| 73 | |
| 74 | const error = new Error('Invalid username or password'); |
| 75 | throw error; |
| 76 | } |
| 77 | |
| 78 | export const AUTH_COOKIE = `bulletproof_react_app_token`; |
| 79 |
no test coverage detected