1
0
forked from baron/baron-sso

fix: SSO 팝업 로그인 시 postMessage 흐름 보장 및 콜백 페이지 팝업 대응 #243

This commit is contained in:
2026-02-11 15:41:27 +09:00
parent 6c7e80eb3e
commit 50209a1506
3 changed files with 24 additions and 10 deletions

View File

@@ -10,8 +10,15 @@ function AuthCallbackPage() {
const token = searchParams.get("token");
if (token) {
window.localStorage.setItem("admin_session", token);
// Redirect to home after a short delay or immediately
navigate("/", { replace: true });
// 만약 팝업창에서 실행 중이라면 부모 창에 알리고 닫기
if (window.opener) {
window.opener.postMessage({ type: "LOGIN_SUCCESS", token }, "*");
window.close();
} else {
// 일반 리다이렉트 방식인 경우 홈으로 이동
navigate("/", { replace: true });
}
} else {
console.error("No token found in callback URL");
navigate("/login", { replace: true });

View File

@@ -32,7 +32,11 @@ function LoginPage() {
const handleSSOLogin = (mode: "popup" | "redirect" = "popup") => {
const userfrontUrl = import.meta.env.USERFRONT_URL || "https://sso.hmac.kr";
const callbackUrl = `${window.location.origin}/auth/callback`;
const loginUrl = `${userfrontUrl}/signin?source=adminfront&redirect_uri=${encodeURIComponent(callbackUrl)}`;
// 팝업 방식일 때는 redirect_uri를 보내지 않아야 postMessage 로직이 작동함
const loginUrl = mode === "redirect"
? `${userfrontUrl}/signin?source=adminfront&redirect_uri=${encodeURIComponent(callbackUrl)}`
: `${userfrontUrl}/signin?source=adminfront`;
if (mode === "redirect") {
window.location.href = loginUrl;