forked from baron/baron-sso
adminfront 로그인 페이지에 auto redirect SSO 진입 추가
This commit is contained in:
@@ -14,7 +14,14 @@ function AuthCallbackPage() {
|
|||||||
if (user?.access_token) {
|
if (user?.access_token) {
|
||||||
window.localStorage.setItem("admin_session", user.access_token);
|
window.localStorage.setItem("admin_session", user.access_token);
|
||||||
}
|
}
|
||||||
navigate("/", { replace: true });
|
const returnTo =
|
||||||
|
typeof auth.user?.state === "object" &&
|
||||||
|
auth.user?.state !== null &&
|
||||||
|
"returnTo" in auth.user.state &&
|
||||||
|
typeof auth.user.state.returnTo === "string"
|
||||||
|
? auth.user.state.returnTo
|
||||||
|
: "/";
|
||||||
|
navigate(returnTo, { replace: true });
|
||||||
} else if (auth.error) {
|
} else if (auth.error) {
|
||||||
console.error("Auth Error:", auth.error);
|
console.error("Auth Error:", auth.error);
|
||||||
navigate("/login", { replace: true });
|
navigate("/login", { replace: true });
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import { ExternalLink, LogIn, ShieldHalf } from "lucide-react";
|
import { ExternalLink, LogIn, ShieldHalf } from "lucide-react";
|
||||||
|
import { useEffect, useRef } from "react";
|
||||||
import { useAuth } from "react-oidc-context";
|
import { useAuth } from "react-oidc-context";
|
||||||
|
import { useNavigate, useSearchParams } from "react-router-dom";
|
||||||
import { Button } from "../../components/ui/button";
|
import { Button } from "../../components/ui/button";
|
||||||
import {
|
import {
|
||||||
Card,
|
Card,
|
||||||
@@ -11,10 +13,46 @@ import {
|
|||||||
|
|
||||||
function LoginPage() {
|
function LoginPage() {
|
||||||
const auth = useAuth();
|
const auth = useAuth();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const [searchParams] = useSearchParams();
|
||||||
|
const autoStartedRef = useRef(false);
|
||||||
|
const returnTo = searchParams.get("returnTo") || "/";
|
||||||
|
const shouldAutoLogin = searchParams.get("auto") === "1";
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (auth.isAuthenticated) {
|
||||||
|
navigate(returnTo, { replace: true });
|
||||||
|
}
|
||||||
|
}, [auth.isAuthenticated, navigate, returnTo]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!shouldAutoLogin) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (autoStartedRef.current || auth.isLoading || auth.activeNavigator) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
autoStartedRef.current = true;
|
||||||
|
void auth.signinRedirect({
|
||||||
|
state: {
|
||||||
|
returnTo,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}, [
|
||||||
|
auth,
|
||||||
|
auth.activeNavigator,
|
||||||
|
auth.isLoading,
|
||||||
|
returnTo,
|
||||||
|
shouldAutoLogin,
|
||||||
|
]);
|
||||||
|
|
||||||
const handleSSOLogin = () => {
|
const handleSSOLogin = () => {
|
||||||
// OIDC client-side authentication flow started here
|
void auth.signinRedirect({
|
||||||
auth.signinRedirect();
|
state: {
|
||||||
|
returnTo: "/",
|
||||||
|
},
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user