Fix Bug
This commit is contained in:
@@ -43,21 +43,21 @@ module.exports.login = [
|
||||
const user = await User.findOne({
|
||||
$or: [{ email: username.toLowerCase().trim() }, { national_code: username }, { username }]
|
||||
})
|
||||
if (!user) throw new Error('err')
|
||||
if (!user) throw new Error(_sr.fa.not_found.password)
|
||||
const passwordMatch = await bcrypt.compare(password, user.password)
|
||||
if (!passwordMatch) throw new Error('err')
|
||||
if (!passwordMatch) throw new Error(_sr.fa.not_found.password)
|
||||
const token = await jwt.sign({ _id: user._id }, secretKey, {
|
||||
expiresIn: req.body.remember_me ? '30d' : '7d'
|
||||
})
|
||||
if(!user.scope.includes('gps')){
|
||||
throw new Error('err')
|
||||
throw new Error('شما به این بخش دسترسی ندارید')
|
||||
}
|
||||
user.token = token
|
||||
await user.save()
|
||||
return res.status(200).json({ token })
|
||||
} catch (err) {
|
||||
return res.status(422).json({
|
||||
validation: { username: { msg: _sr.fa.not_found.password } }
|
||||
validation: { username: { msg: err.message } }
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user