protect from zombie auth

This commit is contained in:
Igor Loskutov
2025-09-03 10:53:03 -04:00
parent 611e258d96
commit 0cbbd24c65
9 changed files with 222 additions and 213 deletions

View File

@@ -12,12 +12,12 @@ import { useAuth } from "./AuthProvider";
export function SessionAutoRefresh({
children,
refreshInterval = 20 /* seconds */,
refreshInterval = 5 /* seconds */,
}) {
const auth = useAuth();
const accessTokenExpires =
auth.status === "authenticated" ? auth.accessTokenExpires : null;
console.log("authauth", auth);
const refreshIntervalMs = refreshInterval * 1000;
useEffect(() => {
@@ -25,7 +25,13 @@ export function SessionAutoRefresh({
if (accessTokenExpires !== null) {
const timeLeft = accessTokenExpires - Date.now();
if (timeLeft < refreshIntervalMs) {
auth.update();
auth
.update()
.then(() => {})
.catch((e) => {
// note: 401 won't be considered error here
console.error("error refreshing auth token", e);
});
}
}
}, refreshIntervalMs);