mirror of
https://github.com/open-webui/open-webui
synced 2025-06-15 02:41:30 +00:00
enh: token expiry buffer
This commit is contained in:
parent
d4c3cfbaba
commit
cbe84d7139
@ -7,7 +7,7 @@
|
|||||||
stiffness: 0.05
|
stiffness: 0.05
|
||||||
});
|
});
|
||||||
|
|
||||||
import { onMount, tick, setContext } from 'svelte';
|
import { onMount, tick, setContext, onDestroy } from 'svelte';
|
||||||
import {
|
import {
|
||||||
config,
|
config,
|
||||||
user,
|
user,
|
||||||
@ -454,6 +454,7 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const TOKEN_EXPIRY_BUFFER = 60; // seconds
|
||||||
const checkTokenExpiry = async () => {
|
const checkTokenExpiry = async () => {
|
||||||
const exp = $user?.expires_at; // token expiry time in unix timestamp
|
const exp = $user?.expires_at; // token expiry time in unix timestamp
|
||||||
const now = Math.floor(Date.now() / 1000); // current time in unix timestamp
|
const now = Math.floor(Date.now() / 1000); // current time in unix timestamp
|
||||||
@ -463,7 +464,7 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (now >= exp) {
|
if (now >= exp - TOKEN_EXPIRY_BUFFER) {
|
||||||
const res = await userSignOut();
|
const res = await userSignOut();
|
||||||
user.set(null);
|
user.set(null);
|
||||||
localStorage.removeItem('token');
|
localStorage.removeItem('token');
|
||||||
@ -508,6 +509,9 @@
|
|||||||
if (document.visibilityState === 'visible') {
|
if (document.visibilityState === 'visible') {
|
||||||
isLastActiveTab.set(true); // This tab is now the active tab
|
isLastActiveTab.set(true); // This tab is now the active tab
|
||||||
bc.postMessage('active'); // Notify other tabs that this tab is active
|
bc.postMessage('active'); // Notify other tabs that this tab is active
|
||||||
|
|
||||||
|
// Check token expiry when the tab becomes active
|
||||||
|
checkTokenExpiry();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user