[st] refactor: 인증 처리 로직 공통 패키지로 수정

This commit is contained in:
2026-04-09 18:30:58 +09:00
parent 8965a62d94
commit 207268b7fc
12 changed files with 7698 additions and 5968 deletions
+25 -15
View File
@@ -5,11 +5,11 @@ import {
AUTH_USER_ID,
CLAIM_NAME,
ENDPOINT,
JWT_EXPIRATION_TIME,
} from "@/shared/config";
import { getCookie } from "@/shared/lib";
import { getRemainingMs } from "@common/auth";
import { tokenManager } from "../lib/token-manager";
import { clearAuthToken, setToken, setupRefreshTimer } from "../lib/token-manager";
import type { ILogin,LoginService } from "../model/login-interface";
import { clearTabStorePersist } from "@/store/tab-store";
@@ -30,10 +30,8 @@ export class LoginApiService implements LoginService {
try {
const response = await fetch(`/api/proxy${ENDPOINT.USER_SERVICE.LOGIN}`, {
method: "POST",
body: JSON.stringify({
userId: payload.userId,
password: payload.password,
}),
headers: { "Content-Type": "application/json" },
body: JSON.stringify(payload),
});
const data = await response.json();
@@ -49,12 +47,16 @@ export class LoginApiService implements LoginService {
clearTabStorePersist();
}
tokenManager.setToken(CLAIM_NAME, accessToken);
tokenManager.setToken(AUTH_USER_ID, tokenId);
tokenManager.setupRefreshTimer(
() => this.silentRefresh(),
JWT_EXPIRATION_TIME,
);
setToken(CLAIM_NAME, accessToken);
setToken(AUTH_USER_ID, tokenId);
const remainingMs = getRemainingMs(accessToken);
if (remainingMs > 0) {
setupRefreshTimer(
() => this.silentRefresh(),
remainingMs,
);
}
} catch (error) {
if (error instanceof AxiosError) {
throw new Error(`Login failed: ${error.response?.data?.message}`);
@@ -78,10 +80,18 @@ export class LoginApiService implements LoginService {
throw new Error("Missing required authentication tokens");
}
tokenManager.setToken(CLAIM_NAME, accessToken);
tokenManager.setToken(AUTH_USER_ID, tokenId);
setToken(CLAIM_NAME, accessToken);
setToken(AUTH_USER_ID, tokenId);
const remainingMs = getRemainingMs(accessToken);
if (remainingMs > 0) {
setupRefreshTimer(
() => this.silentRefresh(),
remainingMs,
);
}
} catch (error) {
tokenManager.clearAuthToken();
clearAuthToken();
if (error instanceof AxiosError) {
throw new Error(
`Silent refresh failed: ${error.response?.data?.message}`,