|
@@ -100,24 +100,26 @@ app.post('/login', async (req, res) => {
|
|
io.use( async (socket, next) => {
|
|
io.use( async (socket, next) => {
|
|
const token = socket.handshake.auth.token;
|
|
const token = socket.handshake.auth.token;
|
|
const sockets = await io.fetchSockets();
|
|
const sockets = await io.fetchSockets();
|
|
-
|
|
|
|
|
|
+
|
|
if(!token) {
|
|
if(!token) {
|
|
socket.disconnect();
|
|
socket.disconnect();
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
|
|
+console.log('here', token)
|
|
const usersOnline = [];
|
|
const usersOnline = [];
|
|
sockets.map((sock) => {
|
|
sockets.map((sock) => {
|
|
usersOnline.push(sock.user);
|
|
usersOnline.push(sock.user);
|
|
})
|
|
})
|
|
|
|
|
|
-
|
|
|
|
|
|
+
|
|
try {
|
|
try {
|
|
const user = jwt.verify(token, TOKEN_KEY);
|
|
const user = jwt.verify(token, TOKEN_KEY);
|
|
userName = user.userName;
|
|
userName = user.userName;
|
|
const dbUser = await getOneUser(userName);
|
|
const dbUser = await getOneUser(userName);
|
|
|
|
|
|
|
|
+ console.log('here', userName)
|
|
|
|
+
|
|
if(dbUser.isBanned){
|
|
if(dbUser.isBanned){
|
|
socket.disconnect();
|
|
socket.disconnect();
|
|
return;
|
|
return;
|
|
@@ -129,13 +131,10 @@ io.use( async (socket, next) => {
|
|
if(exist) { //&& !user.isAdmin - add for two or more admins
|
|
if(exist) { //&& !user.isAdmin - add for two or more admins
|
|
console.log(exist.userName, 'exist twice entering...')
|
|
console.log(exist.userName, 'exist twice entering...')
|
|
exist.disconnect();
|
|
exist.disconnect();
|
|
- return;
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
} catch(e) {
|
|
} catch(e) {
|
|
console.log(e);
|
|
console.log(e);
|
|
socket.disconnect();
|
|
socket.disconnect();
|
|
- return;
|
|
|
|
}
|
|
}
|
|
next();
|
|
next();
|
|
});
|
|
});
|