summaryrefslogtreecommitdiffstats
path: root/server/lib/authentication.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/lib/authentication.js')
-rw-r--r--server/lib/authentication.js8
1 files changed, 6 insertions, 2 deletions
diff --git a/server/lib/authentication.js b/server/lib/authentication.js
index 5623b1e..0681011 100644
--- a/server/lib/authentication.js
+++ b/server/lib/authentication.js
@@ -92,11 +92,15 @@ module.exports = {
} else if (req.cookies.jwt_hp && req.cookies.jwt_s) {
token = req.cookies.jwt_hp + '.' + req.cookies.jwt_s
} else {
- return res.status(403).send({ auth: false, status: 'TOKEN_MISSING', error_message: 'This service requires a token.' })
+ if (res) return res.status(403).send({ auth: false, status: 'TOKEN_MISSING', error_message: 'This service requires a token.' })
+ else return next(new Error('TOKEN_MISSING'))
}
// Verify the token with the secret.
jwt.verify(token, config.secret, function (err) {
- if (err) return res.status(500).send({ auth: false, status: 'TOKEN_INVALID', error_message: 'The provided token is invalid.' })
+ if (err) {
+ if (res) return res.status(500).send({ auth: false, status: 'TOKEN_INVALID', error_message: 'The provided token is invalid.' })
+ else return next(new Error('TOKEN_INVALID'))
+ }
req.token = token
next()
})