mirror of
https://github.com/stonith404/pingvin-share.git
synced 2025-01-15 01:14:27 -05:00
fix: error when refresh token is expired
This commit is contained in:
parent
237733b53f
commit
0823d28e23
1 changed files with 13 additions and 10 deletions
|
@ -20,17 +20,20 @@ const signOut = () => {
|
|||
};
|
||||
|
||||
const refreshAccessToken = async () => {
|
||||
const currentAccessToken = getCookie("access_token") as string;
|
||||
try {
|
||||
const currentAccessToken = getCookie("access_token") as string;
|
||||
if (
|
||||
currentAccessToken &&
|
||||
(jose.decodeJwt(currentAccessToken).exp ?? 0) * 1000 <
|
||||
Date.now() + 2 * 60 * 1000
|
||||
) {
|
||||
const refreshToken = getCookie("refresh_token");
|
||||
|
||||
if (
|
||||
currentAccessToken &&
|
||||
(jose.decodeJwt(currentAccessToken).exp ?? 0) * 1000 <
|
||||
Date.now() + 2 * 60 * 1000
|
||||
) {
|
||||
const refreshToken = getCookie("refresh_token");
|
||||
|
||||
const response = await api.post("auth/token", { refreshToken });
|
||||
setCookies("access_token", response.data.accessToken);
|
||||
const response = await api.post("auth/token", { refreshToken });
|
||||
setCookies("access_token", response.data.accessToken);
|
||||
}
|
||||
} catch {
|
||||
console.info("Refresh token invalid or expired");
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue