Why is the credentials option required for the CredentialsProvider?

Viewed 90

Many code examples for the NextAuth.js credentials provider that are using custom sign in pages do not include the credentials option in the CredentialsProvider. As stated in the documentiaion (https://next-auth.js.org/providers/credentials#example) the credentials option's purpose is to automatically "generate a suitable form on the sign in page" based on the properties appended to this option. As I am using a custom sign in page I do not need these automaically generated fields because I coded them manually as also suggested in the documentation (https://next-auth.js.org/configuration/pages#credentials-sign-in) As I am using Typescript it is throwing a type error when not providing the credentials option. As I do not need it I would like to leave it out. Is there a solution for my problem or is the credentials option required and needed for other reasons?

Code example with credentials option:

...
providers: [
  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: "jsmith@example.com" }

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

Code example without credentials option:

import CredentialsProvider from "next-auth/providers/credentials";
...
providers: [
  CredentialsProvider({
    name: "Credentials",
    async authorize(credentials, req) {
      const user = { id: 1, name: "J Smith", email: "jsmith@example.com" }

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

PS: Even the name option is not really neccessary when using a custom sign up page. I would like to be able to exclude that too...

0 Answers
Related