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