mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-15 17:16:16 +08:00
fix: reload the page when login token expired (#1839)
This commit is contained in:
@@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user