I'm encountering an issue with my registration and login functionality. Registration works fine, but I receive an error when attempting to log in.
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 even tried clearing my database and switching away from bcryptjs
due to concerns about password encryption causing the problem.
Here is my 'auth.config.ts' file:
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
Next, let's look at the 'auth.ts' file:
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,
})
Finally, we have the 'login.ts' file:
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"}
}
}