Fix model & request for gps controller
This commit is contained in:
@@ -39,6 +39,24 @@ const authentication = {
|
||||
return res401(res, 'unauthorized')
|
||||
}
|
||||
},
|
||||
// check if admin logged in (middleware)
|
||||
async isGPS(req, res, next) {
|
||||
try {
|
||||
const token = req.headers?.authorization
|
||||
if (!token) throw new Error('err')
|
||||
|
||||
const decoded = jwt.verify(token.replace(/^Bearer\s/, ''), authentication.secretKey)
|
||||
if (!decoded) throw new Error('err')
|
||||
|
||||
const user = await User.findById(decoded._id)
|
||||
if (!user || !user.scope.includes('gps')) throw new Error('err')
|
||||
|
||||
req.user_id = decoded._id
|
||||
return next()
|
||||
} catch (err) {
|
||||
return res401(res, 'unauthorized')
|
||||
}
|
||||
},
|
||||
// check if user logged in (middleware)
|
||||
async isUser(req, res, next) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user