(0 , next_auth_react__WEBPACK_IMPORTED_MODULE_3__.signIn) is not a function after Login

  Kiến thức lập trình

I’m having a little bit of trouble on this one, when I register its working, but when I tried to login, I get this error.

TypeError: (0 , next_auth_react__WEBPACK_IMPORTED_MODULE_3__.signIn) is not a function
    at $$ACTION_0 (webpack-internal:///(action-browser)/./actions/login.ts:28:70)
    at endpoint (webpack-internal:///(action-browser)/./node_modules/next/dist/build/webpack/loaders/next-flight-action-entry-loader.js?actions=%5B%5B%22C%3A%5C%5CUsers%5C%5CStudent%5C%5CDesktop%5C%5CnextAuth%5C%5Cauth-tutorial%5C%5Cactions%5C%5Clogin.ts%22%2C%5B%22login%22%2C%22%24%24ACTION_0%22%5D%5D%5D&__client_imported__=true!:9:17)

I tried nuking my database and stop using bcryptjs because I thought it will be the problem after encrypting the password.

auth.config.ts

export default { 
    providers: [
        Credentials({
            async authorize(credentials){
                const validatedFields = LoginSchema.safeParse(credentials);

                if(validatedFields.success){
                    const {email, password} = validatedFields.data;

                    const user = await getUserByEmail(email);
                    if(!user || !user.password) return null;

                    // const passwordsMatch = await bcrypt.compare(
                    //     password,
                    //     user.password
                    // );

                    if(password) return user;
                
                }

                return null
            }
        })
    ] 
} satisfies NextAuthConfig

auth.ts

import NextAuth from "next-auth"
import { PrismaAdapter } from "@auth/prisma-adapter"
import { PrismaClient } from "@prisma/client"
import authConfig from "./auth.config"
import { db } from "./lib/db"
 
 
export const { handlers: {GET, POST}, auth, signIn, signOut } = NextAuth({
  adapter: PrismaAdapter(db),
  session: { strategy: "jwt" },
  ...authConfig,
})

login.ts

export const login = async (values:z.infer<typeof LoginSchema>) => {
    const validatedFields = LoginSchema.safeParse(values)

    if(!validatedFields.success){
        return {error: "Invalid fields!"}

    }

    const {email, password} = validatedFields.data;

    try {
        await signIn("credentials",{
            email,
            password,
            redirectTo:  DEFAULT_LOGIN_REDIRECT
        })
    } catch (error) {
        console.log(error)
        return {error: "Something went wrong"}

    }
}

LEAVE A COMMENT