refactor: Migrate sign-in method to NextAuth direct sign-in

This commit is contained in:
wood chen 2025-02-09 19:12:53 +08:00
parent fc347747c4
commit 3ba0e3ed6b

View File

@ -2,18 +2,12 @@
import { useCallback, useEffect, useState } from "react";
import { useRouter } from "next/navigation";
import { signIn } from "@/actions/user-authorize";
import { useSession } from "next-auth/react";
import { signIn as nextAuthSignIn, useSession } from "next-auth/react";
interface UserAuthorizeProps extends React.HTMLAttributes<HTMLDivElement> {
data: Record<string, any>;
}
interface SignInResult {
error?: string;
ok?: boolean;
}
export function UserAuthorize({
className,
data,
@ -30,7 +24,11 @@ export function UserAuthorize({
}
setIsLoading(true);
try {
const result = (await signIn({ ...data })) as SignInResult;
const result = await nextAuthSignIn("credentials", {
...data,
redirect: false,
});
if (result?.error) {
setError(result.error);
} else {