mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 12:17:08 +00:00
Fix scheduling of token refresh via websocket
This commit is contained in:
@@ -20,8 +20,10 @@ function start (server, pingInterval=30000) {
|
||||
const exp = decoded?.exp;
|
||||
if (exp) {
|
||||
const timeout = (exp*1000 - Date.now()) / 2;
|
||||
socket._jwtRefresh = setTimeout(() => refreshJwt(token), timeout);
|
||||
console.log(`Scheduled JWT refresh in ${timeout/1000} seconds at time ${(new Date(Date.now() + timeout)).toISOString()}`);
|
||||
if (!socket._jwtRefresh) {
|
||||
socket._jwtRefresh = setTimeout(() => refreshJwt(token), timeout);
|
||||
console.log(`Scheduled JWT refresh in ${timeout/1000} seconds at time ${(new Date(Date.now() + timeout)).toISOString()}`);
|
||||
}
|
||||
} else {
|
||||
console.log("Token has no exp claim. Refresh not scheduled");
|
||||
}
|
||||
@@ -76,8 +78,8 @@ function start (server, pingInterval=30000) {
|
||||
|
||||
});
|
||||
socket.on('close', () => {
|
||||
if (socket._jwtTimeout) {
|
||||
clearTimeout(socket._jwtTimeout);
|
||||
if (socket._jwtRefresh) {
|
||||
clearTimeout(socket._jwtRefresh);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user