fix: reload the page when login token expired (#1839)

This commit is contained in:
Himself65
2023-04-06 18:26:53 -05:00
committed by GitHub
parent 5ac36b6f0a
commit efe5444816
10 changed files with 80 additions and 16 deletions
@@ -21,14 +21,22 @@ const revalidate = async () => {
const response = await affineAuth.refreshToken(storage);
if (response) {
setLoginStorage(response);
// todo: need to notify the app that the token has been refreshed
// this is a hack to force a reload
window.location.reload();
}
}
}
return true;
};
export function useAffineRefreshAuthToken() {
export function useAffineRefreshAuthToken(
// every 30 seconds, check if the token is expired
refreshInterval = 30 * 1000
) {
useSWR('autoRefreshToken', {
fetcher: revalidate,
refreshInterval,
});
}