summaryrefslogtreecommitdiffstats
path: root/server/lib/authentication.js
diff options
context:
space:
mode:
authorUdo Walter2018-11-26 20:12:31 +0100
committerUdo Walter2018-11-26 20:12:31 +0100
commit82648439b945cc5d049886f7e79c2f0dd9d14ff9 (patch)
treeebeb33ba47bef73306d004b230726ddad5d16bfa /server/lib/authentication.js
parent[webapp] small bugfix (diff)
downloadbas-82648439b945cc5d049886f7e79c2f0dd9d14ff9.tar.gz
bas-82648439b945cc5d049886f7e79c2f0dd9d14ff9.tar.xz
bas-82648439b945cc5d049886f7e79c2f0dd9d14ff9.zip
[webapp+server] Add first implementation of a websocket to alert webclients of events
and to synchronize notification across multiple webapp instances of the same user
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()
})