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> => {
router.post('/sessions/', async (req : Request, res : Response):Promise<object> => {
console.log('req.body',req.body)
const user:User|null = await dataSource.getRepository(User)
const {email, password} = req.body;
const user = await dataSource
.createQueryBuilder()
.select()
.addSelect("User.password")
.select("user")
.from(User, "user")
.where("user.email = :email", { email: email })
.getOne()
if(!user) return res.status(404).send({Message:'user not found'})
if (!user) return res.status(400).send({
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"
})
const isMatch:boolean = await user.checkPassword(password);
if (!isMatch) return res.status(400).send({
error: "Wrong Password"
})
const userToFront:User|null = await dataSource.manager.findOneBy(User, {
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