feat: refresh 로직 수정

This commit is contained in:
2025-03-12 13:29:34 +09:00
parent 6e41c09157
commit 108e2a8746
9 changed files with 154 additions and 24 deletions
@@ -31,7 +31,7 @@ export class LoginApiService implements LoginService {
const tokenId = data[AUTH_USER_ID];
if (!accessToken || !tokenId) {
throw new Error("Missing required authentication tokens");
throw new Error("[login] Missing required authentication tokens");
}
tokenManager.setToken(CLAIM_NAME, accessToken);
@@ -62,13 +62,16 @@ export class LoginApiService implements LoginService {
const tokenId = data[AUTH_USER_ID];
if (!accessToken || !tokenId) {
throw new Error("Missing required authentication tokens");
throw new Error(
"[silentRefresh] Missing required authentication tokens",
);
}
tokenManager.setToken(CLAIM_NAME, accessToken);
tokenManager.setToken(AUTH_USER_ID, tokenId);
} catch (error) {
console.warn("Token has expired, logging out.");
tokenManager.clearAuthToken();
if (error instanceof AxiosError) {
throw new Error(
`Silent refresh failed: ${error.response?.data?.message || error.message}`,
@@ -40,12 +40,12 @@ export class TokenManager {
this.refreshTimer = setTimeout(() => {
callback().catch((error) => {
console.error("Silent refresh failed:", error);
this.clearAuth();
this.clearAuthToken();
});
}, expirationTime - 60000);
}
public clearAuth(): void {
public clearAuthToken(): void {
if (this.refreshTimer) {
clearTimeout(this.refreshTimer);
this.refreshTimer = null;