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"],
|
||||
queryFn: async () => {
|
||||
console.debug("[AppLayout] Fetching profile...");
|
||||
@@ -180,11 +184,11 @@ function AppLayout() {
|
||||
const isTest =
|
||||
(window as Window & typeof globalThis & { _IS_TEST_MODE?: boolean })
|
||||
._IS_TEST_MODE === true;
|
||||
|
||||
|
||||
console.debug("[AppLayout] Auth state check:", {
|
||||
isLoading: auth.isLoading,
|
||||
isAuthenticated: auth.isAuthenticated,
|
||||
isTest
|
||||
isTest,
|
||||
});
|
||||
|
||||
if (!auth.isLoading && !auth.isAuthenticated && !isTest) {
|
||||
|
||||
@@ -11,7 +11,7 @@ function AuthCallbackPage() {
|
||||
console.debug("[AuthCallbackPage] State:", {
|
||||
isAuthenticated: auth.isAuthenticated,
|
||||
isLoading: auth.isLoading,
|
||||
error: auth.error
|
||||
error: auth.error,
|
||||
});
|
||||
if (auth.isAuthenticated) {
|
||||
// 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"
|
||||
? auth.user.state.returnTo
|
||||
: "/";
|
||||
console.info("[AuthCallbackPage] Auth successful, navigating to", returnTo);
|
||||
console.info(
|
||||
"[AuthCallbackPage] Auth successful, navigating to",
|
||||
returnTo,
|
||||
);
|
||||
navigate(returnTo, { replace: true });
|
||||
} else if (auth.error) {
|
||||
console.error("[AuthCallbackPage] Auth Error:", auth.error);
|
||||
|
||||
@@ -23,10 +23,13 @@ function LoginPage() {
|
||||
console.debug("[LoginPage] Auth state check:", {
|
||||
isAuthenticated: auth.isAuthenticated,
|
||||
isLoading: auth.isLoading,
|
||||
returnTo
|
||||
returnTo,
|
||||
});
|
||||
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 });
|
||||
}
|
||||
}, [auth.isAuthenticated, navigate, returnTo, auth.isLoading]);
|
||||
|
||||
@@ -11,7 +11,8 @@ const apiClient = axios.create({
|
||||
apiClient.interceptors.request.use(async (config) => {
|
||||
// IdP 중립 Auth 레이어 연동: oidc-client의 userManager에서 최신 토큰을 가져옵니다.
|
||||
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) {
|
||||
config.headers.Authorization = `Bearer ${sessionToken}`;
|
||||
@@ -38,11 +39,13 @@ apiClient.interceptors.response.use(
|
||||
(response) => response,
|
||||
async (error) => {
|
||||
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");
|
||||
|
||||
|
||||
// oidc-client의 유저 상태도 제거하여 isAuthenticated를 false로 만듭니다.
|
||||
// 이를 통해 LoginPage에서의 무한 리다이렉션 루프를 방지합니다.
|
||||
await userManager.removeUser();
|
||||
@@ -51,7 +54,10 @@ apiClient.interceptors.response.use(
|
||||
const isLoginPath = window.location.pathname === "/login";
|
||||
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,7 @@ import { UserManager, WebStorageStateStore } from "oidc-client-ts";
|
||||
import type { AuthProviderProps } from "react-oidc-context";
|
||||
|
||||
export const oidcConfig: AuthProviderProps = {
|
||||
authority:
|
||||
import.meta.env.VITE_OIDC_AUTHORITY || "https://sso.hmac.kr/oidc", // Gateway Proxy URL
|
||||
authority: import.meta.env.VITE_OIDC_AUTHORITY || "https://sso.hmac.kr/oidc", // Gateway Proxy URL
|
||||
client_id: import.meta.env.VITE_OIDC_CLIENT_ID || "adminfront",
|
||||
redirect_uri: `${window.location.origin}/auth/callback`,
|
||||
response_type: "code",
|
||||
|
||||
@@ -29,7 +29,9 @@ export function shouldAttemptSlidingSessionRenew({
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -50,7 +52,9 @@ export function shouldAttemptSlidingSessionRenew({
|
||||
return false;
|
||||
}
|
||||
|
||||
console.info(`[sessionSliding] Attempting sliding session renewal. Remaining: ${remainingMin}m`);
|
||||
console.info(
|
||||
`[sessionSliding] Attempting sliding session renewal. Remaining: ${remainingMin}m`,
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -70,7 +74,9 @@ export function shouldAttemptUnlimitedSessionRenew({
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -78,7 +84,9 @@ export function shouldAttemptUnlimitedSessionRenew({
|
||||
const remainingMin = Math.floor(remainingMs / 1000 / 60);
|
||||
|
||||
if (remainingMs <= 0) {
|
||||
console.debug("[sessionSliding] Session already expired, skipping unlimited renew");
|
||||
console.debug(
|
||||
"[sessionSliding] Session already expired, skipping unlimited renew",
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -91,6 +99,8 @@ export function shouldAttemptUnlimitedSessionRenew({
|
||||
return false;
|
||||
}
|
||||
|
||||
console.info(`[sessionSliding] Attempting unlimited session renewal. Remaining: ${remainingMin}m`);
|
||||
console.info(
|
||||
`[sessionSliding] Attempting unlimited session renewal. Remaining: ${remainingMin}m`,
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user