diff --git a/src/components/auth/user-authorize.tsx b/src/components/auth/user-authorize.tsx index dd565c6..8c7bc59 100644 --- a/src/components/auth/user-authorize.tsx +++ b/src/components/auth/user-authorize.tsx @@ -5,6 +5,8 @@ import { useRouter } from "next/navigation"; import { signIn } from "@/actions/user-authorize"; import { useSession } from "next-auth/react"; +import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; + interface UserAuthorizeProps extends React.HTMLAttributes { data: Record; } @@ -17,6 +19,7 @@ export function UserAuthorize({ const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(null); const { update } = useSession(); + const router = useRouter(); const signInCallback = useCallback(async () => { if (isLoading) { @@ -27,27 +30,53 @@ export function UserAuthorize({ await signIn({ ...data, redirectTo: "/dashboard" }); // 更新 session await update(); + // 强制刷新页面状态 + router.refresh(); setIsLoading(false); } catch (error) { setError(error); setIsLoading(false); } - }, [data, isLoading, update]); + }, [data, isLoading, update, router]); useEffect(() => { - const timer = setTimeout(signInCallback, 5); - return () => { - clearTimeout(timer); - }; + // 直接执行登录回调 + signInCallback(); }, [signInCallback]); + if (error) { + return ( + + +
+
+
+ + 授权失败 + +
+ +

+ 登录异常,授权失败!请稍后重试。 +

+
+
+ ); + } + return ( - <> - {error ? ( -

登录异常,授权失败!

- ) : ( -

账号信息验证中,准备跳转中,请稍等...

- )} - + + +
+
+
+ 正在处理授权 +
+ +

+ {isLoading ? "请稍候,我们正在处理您的授权请求" : "正在跳转..."} +

+
+
); } diff --git a/src/components/layout/nav-bar.tsx b/src/components/layout/nav-bar.tsx index 563b732..c28f052 100644 --- a/src/components/layout/nav-bar.tsx +++ b/src/components/layout/nav-bar.tsx @@ -21,13 +21,18 @@ import { ThemeToggle } from "../theme-toggle"; import { Button } from "../ui/button"; export function NavBar() { - const { data: session, status } = useSession(); + const { data: session, status, update } = useSession(); const router = useRouter(); const pathname = usePathname(); const user = session?.user; + useEffect(() => { + update(); + }, [update]); + const handleSignOut = async () => { await signOut({ redirect: false }); + router.refresh(); router.push("/"); };