Merge branch 'iipbs/wr/dev'

This commit is contained in:
2026-07-02 18:08:03 +09:00
4 changed files with 34 additions and 26 deletions
+6 -6
View File
@@ -35,11 +35,11 @@ async function handler(
// silent refresh
if (isRefreshHandler) {
const refreshToken = cookieStore.get(REFRESH_TOKEN);
const refreshToken = cookieStore.get(REFRESH_TOKEN); // "refresh-token"
console.log("refreshToken", refreshToken?.value);
headers[CLAIM_NAME] = refreshToken?.value ?? "";
headers[CLAIM_NAME] = refreshToken?.value ?? ""; // "Authorization"
if (!headers[CLAIM_NAME]) {
if (!headers[CLAIM_NAME]) { // "Authorization"
return NextResponse.json({ message: "Can't refresh" }, { status: 401 });
}
}
@@ -62,9 +62,9 @@ async function handler(
);
}
const accessToken = result.headers.get(ACCESS_TOKEN);
const refreshToken = result.headers.get(REFRESH_TOKEN);
const userId = result.headers.get(AUTH_USER_ID);
const accessToken = result.headers.get(ACCESS_TOKEN); // "access-token"
const refreshToken = result.headers.get(REFRESH_TOKEN); // "refresh-token" 신규 받아온 token
const userId = result.headers.get(AUTH_USER_ID); // "token-id"
if (accessToken && userId) {
const response = NextResponse.json({
+4 -1
View File
@@ -49,7 +49,10 @@ function CommonCodeInitializer() {
useEffect(() => {
if (isLoginPage) return;
if (isInit) return;
initCommonCodes();
setTimeout(() => {
initCommonCodes();
}, 3000); // 3초 후에 하는 것으로 왜냐하면 로그인 처리가 먼저 되어야 하기 때문에
}, [isInit, initCommonCodes, isLoginPage]);
return null;
+23 -18
View File
@@ -1,7 +1,7 @@
import type { LoginService, ILogin } from "../model/login-interface";
import { tokenManager } from "../lib/token-manager";
import {PROXY_HOST, ACCESS_TOKEN, AUTH_USER_ID,SITE_ID, CLAIM_NAME, ENDPOINT, JWT_EXPIRATION_TIME } from "../../../shared/config";
import { ACCESS_TOKEN, AUTH_USER_ID, SITE_ID, CLAIM_NAME, ENDPOINT,JWT_EXPIRATION_TIME } from "../../../shared/config";
export class LoginApiService implements LoginService {
private static instance: LoginApiService;
@@ -18,31 +18,33 @@ export class LoginApiService implements LoginService {
public async login(payload: ILogin): Promise<void> {
try {
tokenManager.clearAuthToken();
const response = await fetch( PROXY_HOST+ ENDPOINT.USER_SERVICE.LOGIN, {
const response = await fetch(`/api/proxy${ENDPOINT.USER_SERVICE.LOGIN}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
"X-Site-Id": SITE_ID,
},
body: JSON.stringify({
userId: payload.userId,
password: payload.password,
}),
});
// const data = response.headers.get(ACCESS_TOKEN);
const accessToken = response.headers.get(ACCESS_TOKEN);
const tokenId = response.headers.get(AUTH_USER_ID);
const data = await response.json();
if (!response.ok) {
throw new Error(data?.message ?? "Login failed");
}
const accessToken = data[ACCESS_TOKEN];
const tokenId = data[AUTH_USER_ID];
if (!accessToken || !tokenId) {
throw new Error("Missing required authentication tokens");
}
tokenManager.setToken(CLAIM_NAME, accessToken)
tokenManager.setToken(AUTH_USER_ID, tokenId)
tokenManager.setToken("site-id-key", SITE_ID)
tokenManager.setupRefreshTimer(
() => this.silentRefresh(),
JWT_EXPIRATION_TIME,
);
tokenManager.setToken(CLAIM_NAME, accessToken);
tokenManager.setToken(AUTH_USER_ID, tokenId);
tokenManager.setToken("site-id-key", SITE_ID);
tokenManager.setupRefreshTimer(() => this.silentRefresh(),JWT_EXPIRATION_TIME );
} catch (error) {
throw new Error(`Login failed: ${error}`);
@@ -54,17 +56,19 @@ export class LoginApiService implements LoginService {
console.log(' silentRefresh ')
try {
const response = await fetch(PROXY_HOST+
`${ENDPOINT.USER_SERVICE.SILENT_REFRESH}`,
const response = await fetch(
`/api/proxy${ENDPOINT.USER_SERVICE.SILENT_REFRESH}`,
{
method: "PUT",
headers: {
"X-Site-Id": SITE_ID,
},
},
);
const data = await response.json();
if (!response.ok) {
throw new Error(data?.message ?? "Silent refresh failed");
}
const accessToken = data[ACCESS_TOKEN];
const tokenId = data[AUTH_USER_ID];
@@ -74,6 +78,7 @@ export class LoginApiService implements LoginService {
tokenManager.setToken(CLAIM_NAME, accessToken);
tokenManager.setToken(AUTH_USER_ID, tokenId);
tokenManager.setupRefreshTimer(() => this.silentRefresh(),JWT_EXPIRATION_TIME);
} catch (error) {
tokenManager.clearAuthToken();
throw new Error(`Silent refresh failed: ${error}`);
+1 -1
View File
@@ -82,4 +82,4 @@ export const ENDPOINT = {
};
export const JWT_EXPIRATION_TIME = 3600000;
export const JWT_EXPIRATION_TIME = 1800000;