From 1050a8f6af38b74342d032f999a742051ed00a05 Mon Sep 17 00:00:00 2001 From: wood chen Date: Fri, 21 Feb 2025 22:28:02 +0800 Subject: [PATCH] feat: Add admin redirect and refactor authentication layout and components --- src/app/(auth)/authorize/metadata.ts | 6 --- src/app/(auth)/authorize/page.tsx | 23 +++++++-- src/app/(auth)/layout.tsx | 1 + src/app/(auth)/sign-in/metadata.ts | 6 --- src/components/auth/user-auth-form.tsx | 49 +++++++++--------- src/components/auth/user-authorize.tsx | 71 ++++++++++++-------------- 6 files changed, 74 insertions(+), 82 deletions(-) delete mode 100644 src/app/(auth)/authorize/metadata.ts delete mode 100644 src/app/(auth)/sign-in/metadata.ts diff --git a/src/app/(auth)/authorize/metadata.ts b/src/app/(auth)/authorize/metadata.ts deleted file mode 100644 index f2a0c02..0000000 --- a/src/app/(auth)/authorize/metadata.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { Metadata } from "next"; - -export const metadata: Metadata = { - title: "Auth – Q58论坛", - description: "Sign in to your account", -}; diff --git a/src/app/(auth)/authorize/page.tsx b/src/app/(auth)/authorize/page.tsx index b1ac047..8c18541 100644 --- a/src/app/(auth)/authorize/page.tsx +++ b/src/app/(auth)/authorize/page.tsx @@ -1,11 +1,20 @@ -"use client"; - +import { Suspense } from "react"; +import { Metadata } from "next"; import Link from "next/link"; import { MessageCircleCode } from "lucide-react"; -import { UserAuthForm } from "@/components/auth/user-auth-form"; +import { UserAuthorize } from "@/components/auth/user-authorize"; -export default function AuthPage() { +type Props = { + searchParams: { [key: string]: string | string[] | undefined }; +}; + +export const metadata: Metadata = { + title: `Auth – Q58论坛`, + description: "Sign in to your account", +}; + +export default function AuthPage({ searchParams }: Props) { return (
@@ -15,7 +24,11 @@ export default function AuthPage() { Q58论坛
- +
+ + + +

By clicking continue, you agree to our{" "} { + React.startTransition(async () => { + const response = await fetch("/api/auth/q58", { method: "POST" }); + if (!response.ok || response.status !== 200) { + setIsLoading(false); + toast({ + variant: "destructive", + title: "内部服务异常", + description: response.statusText, + }); + } else { + let data: DiscourseData = await response.json(); + router.push(data.sso_url); } - - const data = await response.json(); - window.location.href = data.sso_url; - } catch (error) { - console.error("登录错误:", error); - toast({ - title: "登录失败", - description: "登录过程中发生错误,请稍后重试", - variant: "destructive", - }); - setIsLoading(false); - } - } + }); + }; return (