1
0
mirror of https://github.com/stonith404/pingvin-share.git synced 2024-07-04 08:20:13 +02:00

fix: error when refresh token is expired

This commit is contained in:
Elias Schneider 2022-10-11 14:44:12 +02:00
parent 237733b53f
commit 0823d28e23

View File

@ -20,17 +20,20 @@ const signOut = () => {
}; };
const refreshAccessToken = async () => { 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 ( const response = await api.post("auth/token", { refreshToken });
currentAccessToken && setCookies("access_token", response.data.accessToken);
(jose.decodeJwt(currentAccessToken).exp ?? 0) * 1000 < }
Date.now() + 2 * 60 * 1000 } catch {
) { console.info("Refresh token invalid or expired");
const refreshToken = getCookie("refresh_token");
const response = await api.post("auth/token", { refreshToken });
setCookies("access_token", response.data.accessToken);
} }
}; };