mirror of
https://github.com/woodchen-ink/Q58Connect.git
synced 2025-07-18 05:51:55 +08:00
feat: Add UserAuthForm to authorize page and enhance SSO/OAuth login handling
This commit is contained in:
parent
80e281f986
commit
465bf1dff5
@ -5,6 +5,8 @@ import Link from "next/link";
|
||||
import { useRouter, useSearchParams } from "next/navigation";
|
||||
import { MessageCircleCode } from "lucide-react";
|
||||
|
||||
import { UserAuthForm } from "@/components/auth/user-auth-form";
|
||||
|
||||
export default function AuthPage() {
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
@ -12,6 +14,7 @@ export default function AuthPage() {
|
||||
useEffect(() => {
|
||||
// 如果有 OAuth 参数,重定向回 /oauth/authorize
|
||||
if (searchParams.has("response_type") && searchParams.has("client_id")) {
|
||||
console.log("检测到 OAuth 参数,准备重定向到 /oauth/authorize");
|
||||
router.replace(`/oauth/authorize?${searchParams.toString()}`);
|
||||
return;
|
||||
}
|
||||
@ -26,6 +29,7 @@ export default function AuthPage() {
|
||||
<span style={{ fontFamily: "Bahamas Bold" }}>Q58论坛</span>
|
||||
</div>
|
||||
</div>
|
||||
<UserAuthForm />
|
||||
<p className="px-8 text-center text-sm text-muted-foreground">
|
||||
By clicking continue, you agree to our{" "}
|
||||
<Link
|
||||
|
@ -3,6 +3,7 @@
|
||||
import * as React from "react";
|
||||
import { useRouter, useSearchParams } from "next/navigation";
|
||||
import { Loader2, MessageCircleCode } from "lucide-react";
|
||||
import { signIn } from "next-auth/react";
|
||||
|
||||
import { cn } from "@/lib/utils";
|
||||
import { useToast } from "@/hooks/use-toast";
|
||||
@ -21,11 +22,28 @@ export function UserAuthForm({
|
||||
const { toast } = useToast();
|
||||
const searchParams = useSearchParams();
|
||||
|
||||
async function signIn() {
|
||||
async function handleSignIn() {
|
||||
try {
|
||||
const body: Record<string, any> = {};
|
||||
// 如果有 SSO 参数,使用 credentials provider 登录
|
||||
if (searchParams.has("sso") && searchParams.has("sig")) {
|
||||
console.log("检测到 SSO 参数,使用 credentials provider 登录");
|
||||
const result = await signIn("credentials", {
|
||||
sso: searchParams.get("sso"),
|
||||
sig: searchParams.get("sig"),
|
||||
redirect: false,
|
||||
});
|
||||
|
||||
// 如果有 OAuth 参数,作为 return_url 传递
|
||||
if (result?.error) {
|
||||
throw new Error(result.error);
|
||||
}
|
||||
|
||||
// 登录成功后刷新页面
|
||||
router.refresh();
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果有 OAuth 参数,发起 SSO 登录
|
||||
const body: Record<string, any> = {};
|
||||
if (searchParams.has("response_type") && searchParams.has("client_id")) {
|
||||
body.return_url = `/oauth/authorize?${searchParams.toString()}`;
|
||||
console.log("正在处理 OAuth 登录,return_url:", body.return_url);
|
||||
@ -70,7 +88,7 @@ export function UserAuthForm({
|
||||
className={cn(buttonVariants({ variant: "outline" }))}
|
||||
onClick={() => {
|
||||
setIsLoading(true);
|
||||
signIn();
|
||||
handleSignIn();
|
||||
}}
|
||||
disabled={isLoading}
|
||||
>
|
||||
|
Loading…
x
Reference in New Issue
Block a user