get user from zod usermodel parsed
This commit is contained in:
parent
c8f242705f
commit
19db116ec4
|
|
@ -6,19 +6,17 @@ import { User } from '@prisma/client';
|
||||||
|
|
||||||
const login = async (req: Request, res: Response) => {
|
const login = async (req: Request, res: Response) => {
|
||||||
try {
|
try {
|
||||||
UserLoginModel.parse(req.body);
|
const userInfo = UserLoginModel.parse(req.body);
|
||||||
const user: User | null = await getUser(req.body.email);
|
const user: User | null = await getUser(userInfo.email);
|
||||||
if (user === null) {
|
if (user === null) {
|
||||||
return res.status(401).send('User not found');
|
return res.status(401).send('User not found');
|
||||||
}
|
}
|
||||||
const isValid = await comparePassword(req.body.password, user.password);
|
const isValid = await comparePassword(userInfo.password, user.password);
|
||||||
if (!isValid) {
|
if (!isValid) {
|
||||||
return res.status(401).send('Invalid password');
|
return res.status(401).send('Invalid password');
|
||||||
}
|
}
|
||||||
return res.status(200).send(user);
|
return res.status(200).send(user);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
|
||||||
|
|
||||||
return res.status(500).send(error);
|
return res.status(500).send(error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue