forked from baron/baron-sso
style: fix formatting issues caught by biome in adminfront
This commit is contained in:
@@ -80,7 +80,11 @@ function AppLayout() {
|
|||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const { data: profile, isLoading: isProfileLoading, error: profileError } = useQuery({
|
const {
|
||||||
|
data: profile,
|
||||||
|
isLoading: isProfileLoading,
|
||||||
|
error: profileError,
|
||||||
|
} = useQuery({
|
||||||
queryKey: ["me"],
|
queryKey: ["me"],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
console.debug("[AppLayout] Fetching profile...");
|
console.debug("[AppLayout] Fetching profile...");
|
||||||
@@ -180,11 +184,11 @@ function AppLayout() {
|
|||||||
const isTest =
|
const isTest =
|
||||||
(window as Window & typeof globalThis & { _IS_TEST_MODE?: boolean })
|
(window as Window & typeof globalThis & { _IS_TEST_MODE?: boolean })
|
||||||
._IS_TEST_MODE === true;
|
._IS_TEST_MODE === true;
|
||||||
|
|
||||||
console.debug("[AppLayout] Auth state check:", {
|
console.debug("[AppLayout] Auth state check:", {
|
||||||
isLoading: auth.isLoading,
|
isLoading: auth.isLoading,
|
||||||
isAuthenticated: auth.isAuthenticated,
|
isAuthenticated: auth.isAuthenticated,
|
||||||
isTest
|
isTest,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!auth.isLoading && !auth.isAuthenticated && !isTest) {
|
if (!auth.isLoading && !auth.isAuthenticated && !isTest) {
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ function AuthCallbackPage() {
|
|||||||
console.debug("[AuthCallbackPage] State:", {
|
console.debug("[AuthCallbackPage] State:", {
|
||||||
isAuthenticated: auth.isAuthenticated,
|
isAuthenticated: auth.isAuthenticated,
|
||||||
isLoading: auth.isLoading,
|
isLoading: auth.isLoading,
|
||||||
error: auth.error
|
error: auth.error,
|
||||||
});
|
});
|
||||||
if (auth.isAuthenticated) {
|
if (auth.isAuthenticated) {
|
||||||
// Save token to localStorage for existing API clients that might still use it
|
// Save token to localStorage for existing API clients that might still use it
|
||||||
@@ -26,7 +26,10 @@ function AuthCallbackPage() {
|
|||||||
typeof auth.user.state.returnTo === "string"
|
typeof auth.user.state.returnTo === "string"
|
||||||
? auth.user.state.returnTo
|
? auth.user.state.returnTo
|
||||||
: "/";
|
: "/";
|
||||||
console.info("[AuthCallbackPage] Auth successful, navigating to", returnTo);
|
console.info(
|
||||||
|
"[AuthCallbackPage] Auth successful, navigating to",
|
||||||
|
returnTo,
|
||||||
|
);
|
||||||
navigate(returnTo, { replace: true });
|
navigate(returnTo, { replace: true });
|
||||||
} else if (auth.error) {
|
} else if (auth.error) {
|
||||||
console.error("[AuthCallbackPage] Auth Error:", auth.error);
|
console.error("[AuthCallbackPage] Auth Error:", auth.error);
|
||||||
|
|||||||
@@ -23,10 +23,13 @@ function LoginPage() {
|
|||||||
console.debug("[LoginPage] Auth state check:", {
|
console.debug("[LoginPage] Auth state check:", {
|
||||||
isAuthenticated: auth.isAuthenticated,
|
isAuthenticated: auth.isAuthenticated,
|
||||||
isLoading: auth.isLoading,
|
isLoading: auth.isLoading,
|
||||||
returnTo
|
returnTo,
|
||||||
});
|
});
|
||||||
if (auth.isAuthenticated) {
|
if (auth.isAuthenticated) {
|
||||||
console.info("[LoginPage] User is authenticated, redirecting to", returnTo);
|
console.info(
|
||||||
|
"[LoginPage] User is authenticated, redirecting to",
|
||||||
|
returnTo,
|
||||||
|
);
|
||||||
navigate(returnTo, { replace: true });
|
navigate(returnTo, { replace: true });
|
||||||
}
|
}
|
||||||
}, [auth.isAuthenticated, navigate, returnTo, auth.isLoading]);
|
}, [auth.isAuthenticated, navigate, returnTo, auth.isLoading]);
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ const apiClient = axios.create({
|
|||||||
apiClient.interceptors.request.use(async (config) => {
|
apiClient.interceptors.request.use(async (config) => {
|
||||||
// IdP 중립 Auth 레이어 연동: oidc-client의 userManager에서 최신 토큰을 가져옵니다.
|
// IdP 중립 Auth 레이어 연동: oidc-client의 userManager에서 최신 토큰을 가져옵니다.
|
||||||
const user = await userManager.getUser();
|
const user = await userManager.getUser();
|
||||||
const sessionToken = user?.access_token || window.localStorage.getItem("admin_session");
|
const sessionToken =
|
||||||
|
user?.access_token || window.localStorage.getItem("admin_session");
|
||||||
|
|
||||||
if (sessionToken) {
|
if (sessionToken) {
|
||||||
config.headers.Authorization = `Bearer ${sessionToken}`;
|
config.headers.Authorization = `Bearer ${sessionToken}`;
|
||||||
@@ -38,11 +39,13 @@ apiClient.interceptors.response.use(
|
|||||||
(response) => response,
|
(response) => response,
|
||||||
async (error) => {
|
async (error) => {
|
||||||
if (error.response?.status === 401) {
|
if (error.response?.status === 401) {
|
||||||
console.warn("[apiClient] 401 Unauthorized detected. Clearing session state.");
|
console.warn(
|
||||||
|
"[apiClient] 401 Unauthorized detected. Clearing session state.",
|
||||||
|
);
|
||||||
|
|
||||||
// 로컬 스토리지의 세션 키 제거
|
// 로컬 스토리지의 세션 키 제거
|
||||||
window.localStorage.removeItem("admin_session");
|
window.localStorage.removeItem("admin_session");
|
||||||
|
|
||||||
// oidc-client의 유저 상태도 제거하여 isAuthenticated를 false로 만듭니다.
|
// oidc-client의 유저 상태도 제거하여 isAuthenticated를 false로 만듭니다.
|
||||||
// 이를 통해 LoginPage에서의 무한 리다이렉션 루프를 방지합니다.
|
// 이를 통해 LoginPage에서의 무한 리다이렉션 루프를 방지합니다.
|
||||||
await userManager.removeUser();
|
await userManager.removeUser();
|
||||||
@@ -51,7 +54,10 @@ apiClient.interceptors.response.use(
|
|||||||
const isLoginPath = window.location.pathname === "/login";
|
const isLoginPath = window.location.pathname === "/login";
|
||||||
|
|
||||||
if (!isAuthPath && !isLoginPath) {
|
if (!isAuthPath && !isLoginPath) {
|
||||||
console.info("[apiClient] Redirecting to /login from", window.location.pathname);
|
console.info(
|
||||||
|
"[apiClient] Redirecting to /login from",
|
||||||
|
window.location.pathname,
|
||||||
|
);
|
||||||
window.location.href = "/login";
|
window.location.href = "/login";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,7 @@ import { UserManager, WebStorageStateStore } from "oidc-client-ts";
|
|||||||
import type { AuthProviderProps } from "react-oidc-context";
|
import type { AuthProviderProps } from "react-oidc-context";
|
||||||
|
|
||||||
export const oidcConfig: AuthProviderProps = {
|
export const oidcConfig: AuthProviderProps = {
|
||||||
authority:
|
authority: import.meta.env.VITE_OIDC_AUTHORITY || "https://sso.hmac.kr/oidc", // Gateway Proxy URL
|
||||||
import.meta.env.VITE_OIDC_AUTHORITY || "https://sso.hmac.kr/oidc", // Gateway Proxy URL
|
|
||||||
client_id: import.meta.env.VITE_OIDC_CLIENT_ID || "adminfront",
|
client_id: import.meta.env.VITE_OIDC_CLIENT_ID || "adminfront",
|
||||||
redirect_uri: `${window.location.origin}/auth/callback`,
|
redirect_uri: `${window.location.origin}/auth/callback`,
|
||||||
response_type: "code",
|
response_type: "code",
|
||||||
|
|||||||
@@ -29,7 +29,9 @@ export function shouldAttemptSlidingSessionRenew({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (typeof expiresAtSec !== "number") {
|
if (typeof expiresAtSec !== "number") {
|
||||||
console.debug("[sessionSliding] expiresAtSec is not a number, skipping renew");
|
console.debug(
|
||||||
|
"[sessionSliding] expiresAtSec is not a number, skipping renew",
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +52,9 @@ export function shouldAttemptSlidingSessionRenew({
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.info(`[sessionSliding] Attempting sliding session renewal. Remaining: ${remainingMin}m`);
|
console.info(
|
||||||
|
`[sessionSliding] Attempting sliding session renewal. Remaining: ${remainingMin}m`,
|
||||||
|
);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +74,9 @@ export function shouldAttemptUnlimitedSessionRenew({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (typeof expiresAtSec !== "number") {
|
if (typeof expiresAtSec !== "number") {
|
||||||
console.debug("[sessionSliding] expiresAtSec is not a number, skipping unlimited renew");
|
console.debug(
|
||||||
|
"[sessionSliding] expiresAtSec is not a number, skipping unlimited renew",
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,7 +84,9 @@ export function shouldAttemptUnlimitedSessionRenew({
|
|||||||
const remainingMin = Math.floor(remainingMs / 1000 / 60);
|
const remainingMin = Math.floor(remainingMs / 1000 / 60);
|
||||||
|
|
||||||
if (remainingMs <= 0) {
|
if (remainingMs <= 0) {
|
||||||
console.debug("[sessionSliding] Session already expired, skipping unlimited renew");
|
console.debug(
|
||||||
|
"[sessionSliding] Session already expired, skipping unlimited renew",
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,6 +99,8 @@ export function shouldAttemptUnlimitedSessionRenew({
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.info(`[sessionSliding] Attempting unlimited session renewal. Remaining: ${remainingMin}m`);
|
console.info(
|
||||||
|
`[sessionSliding] Attempting unlimited session renewal. Remaining: ${remainingMin}m`,
|
||||||
|
);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user