CredentialsProvider is not a function
Answered
Brandt's Cormorant posted this in #help-forum
Brandt's CormorantOP
Whenever I try using Credentials provider, I get this error message:
TypeError: next_auth_providers_credentialsWEBPACK_IMPORTED_MODULE_1 is not a function
This is my auth options in auth.js, I import them in the api/auth/[...nextauth]/route.js, Here's my route.js page:
TypeError: next_auth_providers_credentialsWEBPACK_IMPORTED_MODULE_1 is not a function
import { getServerSession } from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";
export const authOptions = {
secret: process.env.NEXT_AUTH_SECRET,
providers: [
CredentialsProvider({
name: "Credentials",
credentials: {
username: { label: "Email", type: "text", placeholder: "jsmith" },
password: { label: "Password", type: "password" },
},
async authorize(credentials, req) {
//AUTHENTICATE HERE FROM DATABASE
let user = {id: "1", username: "admin", password: "admin"};
if(credentials?.username === user.username && credentials?.password === user.password){
return user;
}
else{
return null;
}
},
}),
],
pages: {
signIn: "/login",
},
};
export const getServerAuthSession = () => getServerSession(authOptions);This is my auth options in auth.js, I import them in the api/auth/[...nextauth]/route.js, Here's my route.js page:
import NextAuth from "next-auth";
import { authOptions } from "auth";
const handler = NextAuth(authOptions);
export { handler as GET, handler as POST };Answered by Brandt's Cormorant
Fixed, I just had to switch the .js file to .ts file (both middleware and options)
2 Replies
Brandt's CormorantOP
Any help?
Brandt's CormorantOP
Fixed, I just had to switch the .js file to .ts file (both middleware and options)
Answer