Fix Bug
This commit is contained in:
@@ -25,18 +25,17 @@ const authentication = {
|
||||
async isAdmin(req, res, next) {
|
||||
try {
|
||||
const token = req.headers?.authorization
|
||||
if (!token) throw new Error('err')
|
||||
if (!token) throw new Error('err1')
|
||||
|
||||
const decoded = jwt.verify(token.replace(/^Bearer\s/, ''), authentication.secretKey)
|
||||
if (!decoded) throw new Error('err')
|
||||
if (!decoded) throw new Error('err2')
|
||||
|
||||
const user = await User.findById(decoded._id)
|
||||
if (!user || !user.scope.includes('admin')) throw new Error('err')
|
||||
if (!user || !user.scope.includes('admin')) throw new Error('err3')
|
||||
|
||||
req.user_id = decoded._id
|
||||
return next()
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
return res401(res, 'unauthorized')
|
||||
}
|
||||
},
|
||||
@@ -44,13 +43,13 @@ const authentication = {
|
||||
async isGPS(req, res, next) {
|
||||
try {
|
||||
const token = req.headers?.authorization
|
||||
if (!token) throw new Error('err')
|
||||
if (!token) throw new Error('err1')
|
||||
|
||||
const decoded = jwt.verify(token.replace(/^Bearer\s/, ''), authentication.secretKey)
|
||||
if (!decoded) throw new Error('err')
|
||||
if (!decoded) throw new Error('err2')
|
||||
|
||||
const user = await User.findById(decoded._id)
|
||||
if (!user || !user.scope.includes('gps')) throw new Error('err')
|
||||
if (!user || !user.scope.includes('gps')) throw new Error('err3')
|
||||
|
||||
req.user_id = decoded._id
|
||||
return next()
|
||||
|
||||
Reference in New Issue
Block a user