mirror of
https://github.com/openstf/stf
synced 2025-10-04 18:29:17 +02:00
Separate websocket to its own role. Necessary because the app was getting pretty big already, but mostly because our Windows PCs don't like to connect to websockets on port 80, which is what we use for the app.
This commit is contained in:
parent
92be2f1b59
commit
984c45b183
13 changed files with 707 additions and 603 deletions
22
lib/roles/websocket/middleware/auth.js
Normal file
22
lib/roles/websocket/middleware/auth.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
var dbapi = require('../../../db/api')
|
||||
|
||||
module.exports = function(socket, next) {
|
||||
var req = socket.request
|
||||
, token = req.session.jwt
|
||||
if (token) {
|
||||
return dbapi.loadUser(token.email)
|
||||
.then(function(user) {
|
||||
if (user) {
|
||||
req.user = user
|
||||
next()
|
||||
}
|
||||
else {
|
||||
next(new Error('Invalid user'))
|
||||
}
|
||||
})
|
||||
.catch(next)
|
||||
}
|
||||
else {
|
||||
next(new Error('Missing authorization token'))
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue