This commit is contained in:
Mr Swift
2024-08-11 16:11:32 +03:30
parent 21a6907d9f
commit 180cb8b5cf
18 changed files with 192 additions and 100 deletions
+4 -4
View File
@@ -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 } }
})
}
}