fix(auth): read redirect on client

This commit is contained in:
2026-06-24 18:57:12 +08:00
parent 38bd9e8ac0
commit 568808ed39
2 changed files with 18 additions and 19 deletions
+16 -6
View File
@@ -4,7 +4,7 @@
*
* 原始 Dart: lib/ui/auth/auth_screen.dart
*/
import { useEffect } from "react";
import { useEffect, useSyncExternalStore } from "react";
import { useRouter } from "next/navigation";
import { MobileShell } from "@/app/_components/core";
@@ -17,14 +17,15 @@ import { Logger } from "@/utils";
const log = new Logger("AppAuthAuthScreen");
export interface AuthScreenProps {
redirectTo?: string | null;
}
export function AuthScreen({ redirectTo = null }: AuthScreenProps) {
export function AuthScreen() {
const state = useAuthState();
const authDispatch = useAuthDispatch();
const router = useRouter();
const redirectTo = useSyncExternalStore(
subscribeLocationSnapshot,
readRedirectFromLocation,
() => null,
);
const safeRedirectTo = getSafeRedirectPath(redirectTo) ?? ROUTES.chat;
// 邮箱登录成功 → 跳转;User hydrate 由根级 <UserAuthSync /> 监听 loginStatus 变化处理。
@@ -70,3 +71,12 @@ function getSafeRedirectPath(redirectTo: string | null | undefined): string | nu
if (!redirectTo.startsWith("/") || redirectTo.startsWith("//")) return null;
return redirectTo;
}
function readRedirectFromLocation(): string | null {
if (typeof window === "undefined") return null;
return new URLSearchParams(window.location.search).get("redirect");
}
function subscribeLocationSnapshot(): () => void {
return () => {};
}
+2 -13
View File
@@ -1,16 +1,5 @@
import { AuthScreen } from "@/app/auth/auth-screen";
interface AuthPageProps {
searchParams: Promise<{
redirect?: string | string[];
}>;
}
export default async function AuthPage({ searchParams }: AuthPageProps) {
const params = await searchParams;
const redirectTo = Array.isArray(params.redirect)
? params.redirect[0]
: params.redirect;
return <AuthScreen redirectTo={redirectTo ?? null} />;
export default function AuthPage() {
return <AuthScreen />;
}