mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-21 04:39:06 +00:00
fix: token refresh locking (#613)
* fix: kv use tls explicit * fix: token refresh locking * remove logs * compile fix * compile fix --------- Co-authored-by: Igor Loskutov <igor.loskutoff@gmail.com>
This commit is contained in:
@@ -15,6 +15,7 @@ const REFRESH_BEFORE = REFRESH_ACCESS_TOKEN_BEFORE;
|
||||
|
||||
export function SessionAutoRefresh({ children }) {
|
||||
const auth = useAuth();
|
||||
|
||||
const accessTokenExpires =
|
||||
auth.status === "authenticated" ? auth.accessTokenExpires : null;
|
||||
|
||||
@@ -23,17 +24,16 @@ export function SessionAutoRefresh({ children }) {
|
||||
// and not too slow (debuggable)
|
||||
const INTERVAL_REFRESH_MS = 5000;
|
||||
const interval = setInterval(() => {
|
||||
if (accessTokenExpires !== null) {
|
||||
const timeLeft = accessTokenExpires - Date.now();
|
||||
if (timeLeft < REFRESH_BEFORE) {
|
||||
auth
|
||||
.update()
|
||||
.then(() => {})
|
||||
.catch((e) => {
|
||||
// note: 401 won't be considered error here
|
||||
console.error("error refreshing auth token", e);
|
||||
});
|
||||
}
|
||||
if (accessTokenExpires === null) return;
|
||||
const timeLeft = accessTokenExpires - Date.now();
|
||||
if (timeLeft < REFRESH_BEFORE) {
|
||||
auth
|
||||
.update()
|
||||
.then(() => {})
|
||||
.catch((e) => {
|
||||
// note: 401 won't be considered error here
|
||||
console.error("error refreshing auth token", e);
|
||||
});
|
||||
}
|
||||
}, INTERVAL_REFRESH_MS);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user