mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2025-12-20 20:29:06 +00:00
fix: sync backend and frontend token refresh logic (#614)
* sync backend and frontend token refresh logic * return react strict mode --------- Co-authored-by: Igor Loskutov <igor.loskutoff@gmail.com>
This commit is contained in:
@@ -9,9 +9,7 @@
|
||||
|
||||
import { useEffect } from "react";
|
||||
import { useAuth } from "./AuthProvider";
|
||||
import { REFRESH_ACCESS_TOKEN_BEFORE } from "./auth";
|
||||
|
||||
const REFRESH_BEFORE = REFRESH_ACCESS_TOKEN_BEFORE;
|
||||
import { shouldRefreshToken } from "./auth";
|
||||
|
||||
export function SessionAutoRefresh({ children }) {
|
||||
const auth = useAuth();
|
||||
@@ -25,8 +23,7 @@ export function SessionAutoRefresh({ children }) {
|
||||
const INTERVAL_REFRESH_MS = 5000;
|
||||
const interval = setInterval(() => {
|
||||
if (accessTokenExpires === null) return;
|
||||
const timeLeft = accessTokenExpires - Date.now();
|
||||
if (timeLeft < REFRESH_BEFORE) {
|
||||
if (shouldRefreshToken(accessTokenExpires)) {
|
||||
auth
|
||||
.update()
|
||||
.then(() => {})
|
||||
|
||||
Reference in New Issue
Block a user