"use client"; import { useEffect, useState } from "react"; import { useRouter } from "next/navigation"; import { handleAuthorizeAction } from "@/actions/authorizing"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { ErrorCard } from "@/components/auth/error-card"; interface AuthorizingProps { oauth: string; clientId: string; scope: string; redirectUri: string; } export function Authorizing({ oauth, clientId, scope, redirectUri, }: AuthorizingProps) { const [error, setError] = useState(null); const [isLoading, setIsLoading] = useState(true); useEffect(() => { const authorize = async () => { try { const result = await handleAuthorizeAction(oauth, clientId, scope); if (result.error) { setError(result.error); } else if (result.redirectUrl) { const url = await result.redirectUrl; window.location.href = url; } else { setError("授权响应无效"); } } catch (err) { console.error("授权过程出错:", err); setError(err instanceof Error ? err.message : "授权过程发生未知错误"); } finally { setIsLoading(false); } }; authorize(); }, [oauth, clientId, scope]); if (error) { return (
); } return (
正在处理授权

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

); }