Skip to content

Commit

Permalink
fix: error when refresh token is expired
Browse files Browse the repository at this point in the history
  • Loading branch information
stonith404 committed Oct 11, 2022
1 parent 237733b commit 0823d28
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions frontend/src/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
};

Expand Down

0 comments on commit 0823d28

Please sign in to comment.