feat: Enhance OAuth authorization error handling with ErrorCard

- Add comprehensive error handling for invalid clients, disabled applications, and mismatched redirect URIs
- Implement ErrorCard component to display detailed error messages during OAuth authorization
- Improve user feedback with specific error types and descriptions
- Replace simple error text with structured error handling
This commit is contained in:
wood chen 2025-02-20 03:13:04 +08:00
parent a82643ada4
commit 7c05f5f70e

View File

@ -3,6 +3,7 @@ import { redirect } from "next/navigation";
import { getClientByClientId } from "@/lib/dto/client"; import { getClientByClientId } from "@/lib/dto/client";
import { getCurrentUser } from "@/lib/session"; import { getCurrentUser } from "@/lib/session";
import { Authorizing } from "@/components/auth/authorizing"; import { Authorizing } from "@/components/auth/authorizing";
import { ErrorCard } from "@/components/auth/error-card";
export interface AuthorizeParams { export interface AuthorizeParams {
oauth: string; oauth: string;
@ -25,7 +26,43 @@ export default async function AuthorizePage({
if (!client) { if (!client) {
return ( return (
<div className="flex min-h-screen items-center justify-center p-4"> <div className="flex min-h-screen items-center justify-center p-4">
<div className="text-center text-red-600"></div> <ErrorCard
title="应用不存在"
description="您尝试访问的应用不存在或已被删除"
redirectUri={searchParams.redirectUri}
error="invalid_client"
errorDescription="应用不存在"
/>
</div>
);
}
// 检查应用是否被禁用
if (!client.enabled) {
return (
<div className="flex min-h-screen items-center justify-center p-4">
<ErrorCard
title="应用已禁用"
description="此应用已被管理员禁用,暂时无法使用"
redirectUri={searchParams.redirectUri}
error="access_denied"
errorDescription="此应用已被禁用"
/>
</div>
);
}
// 检查回调地址是否匹配
if (client.redirectUri !== searchParams.redirectUri) {
return (
<div className="flex min-h-screen items-center justify-center p-4">
<ErrorCard
title="回调地址不匹配"
description="应用提供的回调地址与注册时不符"
redirectUri={searchParams.redirectUri}
error="invalid_request"
errorDescription="回调地址不匹配"
/>
</div> </div>
); );
} }