Search code examples
typescriptnext-auth

Using NextAuth.js CredentialsProvider in TypeScript


I'm using NextAuth JS CredentialsProvider in TypeScript but I got this error..

This expression is not callable.
Type 'typeof import("/Users/developer/nextjs-project/test/node_modules/next-auth/providers/index")' has no call signatures.ts(2349)

enter image description here

Sample code from NextAuth

CredentialsProvider({
      name: "Credentials",
      credentials: {
        username: { label: "Username", type: "text", placeholder: "jsmith" },
        password: { label: "Password", type: "password" }
      },
      async authorize(credentials, req) {
        const user = { id: "1", name: "J Smith", email: "[email protected]" }

        if (user) {
          return user
        } else {
          return null
        }
      }
    })

Solution

  • your import is incorrect you are importing from next-auth/providers. it is rather from next-auth/providers/credentials :

    import CredentialsProvider from "next-auth/providers/credentials";