Commit 3f0ac789 by luoqi

fix(web): 生产(mock 禁用)不再弹 dev "快速登录"框,改提示走宿主 SSO

之前 auth-gate 在"非嵌入+未登录"时强制弹 MockLoginDialog(预设瑞尔/瑞泰硬编码前端),
真生产 PAC_ENABLE_MOCK_LOGIN=false 时框照弹、点了才 10107 报错,体验很怪。
改:探测后端 GET /auth/mock-users(禁用返空)→ mock 禁用时显示 SessionExpired
(请从宿主进入),不弹快速登录框;dev/试部署(mock 开)行为不变。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
parent 94f211ba
Pipeline #3372 failed in 0 seconds
...@@ -6,6 +6,7 @@ import { useAuthStore } from '@/stores/auth-store'; ...@@ -6,6 +6,7 @@ import { useAuthStore } from '@/stores/auth-store';
import { MockLoginDialog } from '@/components/mock-login-dialog'; import { MockLoginDialog } from '@/components/mock-login-dialog';
import { SessionExpired } from '@/components/session-expired'; import { SessionExpired } from '@/components/session-expired';
import { isEmbedded } from '@/lib/embed'; import { isEmbedded } from '@/lib/embed';
import { env } from '@/lib/env';
const Placeholder = () => ( const Placeholder = () => (
<div className="flex h-screen items-center justify-center text-sm text-muted-foreground"> <div className="flex h-screen items-center justify-center text-sm text-muted-foreground">
...@@ -22,6 +23,25 @@ export function AuthGate({ children }: { children: React.ReactNode }) { ...@@ -22,6 +23,25 @@ export function AuthGate({ children }: { children: React.ReactNode }) {
// 强制 first render 输出 Placeholder,mount 完再真正分流。 // 强制 first render 输出 Placeholder,mount 完再真正分流。
const [mounted, setMounted] = useState(false); const [mounted, setMounted] = useState(false);
useEffect(() => setMounted(true), []); useEffect(() => setMounted(true), []);
// 探测后端是否开启 mock 快速登录(禁用时 GET /auth/mock-users 返空)。
// 真生产 PAC_ENABLE_MOCK_LOGIN=false → 不弹 dev "快速登录"框(见下方分流)。
const [mockEnabled, setMockEnabled] = useState<boolean | null>(null);
useEffect(() => {
let cancelled = false;
fetch(new URL('/pac/v1/auth/mock-users', env.apiBaseUrl).toString(), { credentials: 'omit' })
.then((r) => r.json())
.then((j) => {
if (!cancelled) setMockEnabled((j?.data?.users?.length ?? 0) > 0);
})
.catch(() => {
if (!cancelled) setMockEnabled(false);
});
return () => {
cancelled = true;
};
}, []);
if (!mounted) return <Placeholder />; if (!mounted) return <Placeholder />;
// mount 后真正分流: // mount 后真正分流:
...@@ -34,9 +54,13 @@ export function AuthGate({ children }: { children: React.ReactNode }) { ...@@ -34,9 +54,13 @@ export function AuthGate({ children }: { children: React.ReactNode }) {
// 嵌入态(宿主 iframe):不弹 dev 快速登录 —— 会话失效只能回宿主重进,给友好引导 + 重试。 // 嵌入态(宿主 iframe):不弹 dev 快速登录 —— 会话失效只能回宿主重进,给友好引导 + 重试。
if (isEmbedded()) return <SessionExpired />; if (isEmbedded()) return <SessionExpired />;
// 独立打开(dev)未鉴权兜底 —— 透明占位 + 强制 MockLoginDialog // 非嵌入 + 未鉴权:
// 真生产把后端 PAC_ENABLE_MOCK_LOGIN=false,mockLogin 返 10107,dialog 会 toast 错误 // - mock 禁用(真生产)→ 不弹 dev 快速登录,给"请从宿主进入"引导(复用 SessionExpired 文案)。
// 后用户能看到底层占位文案了解需要走宿主 SSO // - 探测中 → 占位。
// - mock 启用(dev / 试部署)→ 下方透明占位 + MockLoginDialog。
if (mockEnabled === false) return <SessionExpired />;
if (mockEnabled === null) return <Placeholder />;
return ( return (
<> <>
<div className="flex h-screen flex-col items-center justify-center gap-2 p-8 text-center"> <div className="flex h-screen flex-col items-center justify-center gap-2 p-8 text-center">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment