fixes
This commit is contained in:
20
src/index.js
20
src/index.js
@@ -35,16 +35,22 @@ wss.on('connection', (client) => {
|
|||||||
let parsed = JSON.parse(message);
|
let parsed = JSON.parse(message);
|
||||||
let token = parsed.token;
|
let token = parsed.token;
|
||||||
let currentGroup = parsed.currentGroup;
|
let currentGroup = parsed.currentGroup;
|
||||||
|
try {
|
||||||
|
if (!jwt.verify(token, config.secret)) {
|
||||||
|
client.send("Invalid token");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!jwt.verify(token, config.secret)) {
|
if (!await UserService.isInGroup(jwt.decode(token, config.secret).login.id, currentGroup)) {
|
||||||
client.send("Invalid token");
|
client.send("Not a member of specified group");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
log.error("Error during connection through websocket.")
|
||||||
|
client.send("Error")
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!await UserService.isInGroup(jwt.decode(token, config.secret).login.id, currentGroup)) {
|
|
||||||
client.send("Not a member of specified group");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
clients.push({
|
clients.push({
|
||||||
socket: client,
|
socket: client,
|
||||||
@@ -69,7 +75,7 @@ const server = app.listen(config.port, () => {
|
|||||||
|
|
||||||
server.on('upgrade', (req, res, head) => {
|
server.on('upgrade', (req, res, head) => {
|
||||||
wss.handleUpgrade(req, res, head, socket => {
|
wss.handleUpgrade(req, res, head, socket => {
|
||||||
wss.emit('connection', socket, request);
|
wss.emit('connection', socket, req);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user