使用原始方法

This commit is contained in:
wood chen 2025-02-21 16:49:18 +08:00
parent 0c98d52a16
commit 0da3da33ef

View File

@ -1,8 +1,7 @@
"use client";
import { useCallback, useEffect, useState } from "react";
import { useRouter } from "next/navigation";
import { signIn as nextAuthSignIn, useSession } from "next-auth/react";
import { signIn } from "@/actions/user-authorize";
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
@ -17,8 +16,6 @@ export function UserAuthorize({
}: UserAuthorizeProps) {
const [isLoading, setIsLoading] = useState<boolean>(false);
const [error, setError] = useState<Error | unknown>(null);
const { update } = useSession();
const router = useRouter();
const signInCallback = useCallback(async () => {
if (isLoading) {
@ -26,29 +23,20 @@ export function UserAuthorize({
}
setIsLoading(true);
try {
const result = await nextAuthSignIn("credentials", {
...data,
redirect: false,
});
if (result?.error) {
setError(result.error);
} else {
// 更新 session
await update();
// 登录成功后重定向到控制台
router.push("/dashboard");
}
await signIn({ ...data, redirectTo: "/dashboard" });
setIsLoading(false);
} catch (error) {
setError(error);
} finally {
setIsLoading(false);
}
}, [data, isLoading, update, router]);
}, []);
useEffect(() => {
signInCallback();
}, [signInCallback]);
const timer = setTimeout(signInCallback, 5);
return () => {
clearTimeout(timer);
};
}, []);
return (
<>