-
+
);
}
diff --git a/src/components/auth/authorizing.tsx b/src/components/auth/authorizing.tsx
index 21b3bd4..a77f724 100644
--- a/src/components/auth/authorizing.tsx
+++ b/src/components/auth/authorizing.tsx
@@ -1,67 +1,60 @@
"use client";
-import { useEffect, useState } from "react";
-import { useRouter } from "next/navigation";
-import { handleAuthorizeAction } from "@/actions/authorizing";
+import { useCallback, useEffect, useState } from "react";
+import { useRouter, useSearchParams } from "next/navigation";
+import { getDiscourseSSOUrl } from "@/actions/discourse-sso-url";
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);
+export function Authorizing() {
+ const router = useRouter();
+ const searchParams = useSearchParams();
+ 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);
- }
- };
+ const signInCallback = useCallback(async () => {
+ try {
+ const url = await getDiscourseSSOUrl(searchParams.toString());
+ router.push(url);
+ } catch (error) {
+ setError(error);
+ setIsLoading(false);
+ }
+ }, [router, searchParams]);
- authorize();
- }, [oauth, clientId, scope]);
+ useEffect(() => {
+ // Delay 3s get sso url go to ...
+ const timer = setTimeout(signInCallback, 3);
+ return () => {
+ clearTimeout(timer);
+ };
+ }, [signInCallback]);
if (error) {
return (
-
-
-
+
+
+
+
+ 授权失败
+
+
+
+
+ {error instanceof Error
+ ? error.message
+ : "授权异常,登录失败!请稍后重试。"}
+
+
+
);
}
return (
-
+
diff --git a/src/components/auth/user-auth-form.tsx b/src/components/auth/user-auth-form.tsx
index 0177179..c63e0d3 100644
--- a/src/components/auth/user-auth-form.tsx
+++ b/src/components/auth/user-auth-form.tsx
@@ -62,7 +62,7 @@ export function UserAuthForm({
) : (
)}{" "}
- Q58
+ Q58论坛
);