Commit 275cabde authored by “Yevgeniy's avatar “Yevgeniy

#23 fix routers/users/ login

parent 8aaec6f3
...@@ -32,25 +32,20 @@ router.post('/', async (req : Request, res : Response):Promise<object> => { ...@@ -32,25 +32,20 @@ router.post('/', async (req : Request, res : Response):Promise<object> => {
router.post('/sessions/', async (req : Request, res : Response):Promise<object> => { router.post('/sessions/', async (req : Request, res : Response):Promise<object> => {
console.log('req.body',req.body) const {email, password} = req.body;
const user = await dataSource
const user:User|null = await dataSource.getRepository(User)
.createQueryBuilder() .createQueryBuilder()
.select() .select("user")
.addSelect("User.password") .from(User, "user")
.where("user.email = :email", { email: email })
.getOne() .getOne()
if(!user) return res.status(404).send({Message:'user not found'})
if (!user) return res.status(400).send({ const isMatch:boolean = await user.checkPassword(password);
messageError: "User does not exist"
})
console.log( "user ",user, 'req.body.password',req.body.password)
const isMatch:boolean = await user.checkPassword(req.body.password);
if (!isMatch) return res.status(400).send({
error: "Wrong Password"
})
if (!isMatch) return res.status(400).send({ if (!isMatch) return res.status(400).send({
error: "Wrong Password" error: "Wrong Password"
}) })
const userToFront:User|null = await dataSource.manager.findOneBy(User, { const userToFront:User|null = await dataSource.manager.findOneBy(User, {
email: req.body.email email: req.body.email
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment