登录页 mode 参数改为服务端直传,消除登录/注册表单切换闪烁
LoginPage 从 searchParams 提取 mode 作为 initialMode prop 传给 LoginClient, 替代客户端 useEffect 从 window.location.search 读取的方式,首次渲染即显示目标表单。 Tested: tsc --noEmit 通过, npm run build 通过
This commit is contained in:
@@ -26,12 +26,13 @@ type Mode = "login" | "signup";
|
||||
|
||||
type LoginClientProps = {
|
||||
nextPath: string;
|
||||
initialMode?: Mode;
|
||||
};
|
||||
|
||||
export function LoginClient({ nextPath }: LoginClientProps) {
|
||||
export function LoginClient({ nextPath, initialMode }: LoginClientProps) {
|
||||
const router = useRouter();
|
||||
const { locale } = useI18n();
|
||||
const [mode, setMode] = useState<Mode>("login");
|
||||
const [mode, setMode] = useState<Mode>(initialMode ?? "login");
|
||||
const [email, setEmail] = useState("");
|
||||
const [password, setPassword] = useState("");
|
||||
const [loading, setLoading] = useState(false);
|
||||
@@ -40,18 +41,6 @@ export function LoginClient({ nextPath }: LoginClientProps) {
|
||||
const [resetSent, setResetSent] = useState(false);
|
||||
const [showPassword, setShowPassword] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof window !== "undefined") {
|
||||
const params = new URLSearchParams(window.location.search);
|
||||
const m = params.get("mode");
|
||||
if (m === "signup") {
|
||||
setMode("signup");
|
||||
} else if (m === "login") {
|
||||
setMode("login");
|
||||
}
|
||||
}
|
||||
}, []);
|
||||
|
||||
const supabaseReady = hasSupabasePublicEnv();
|
||||
const isLogin = mode === "login";
|
||||
const siteOrigin =
|
||||
|
||||
Reference in New Issue
Block a user