When using NextAuth.js with a custom sign in page, some code examples for the credentials provider do not include the credentials option in the CredentialsProvider. According to the documentation (here), the credentials option is meant to automatically "generate a suitable form on the sign in page" based on the specified properties. Since I have manually coded my custom sign in page as recommended in the documentation (here), I do not require the automatically generated fields from the credentials option. However, due to using Typescript, omitting the credentials option results in a type error. Is it possible to exclude this option if not needed, or is it mandatory for other reasons?
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: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e389908e8a978ba3869b828e938f86ce899491">[email protected]</a>" }
if (user) {
return user
} else {
return null
}
}
})
]
...
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: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9cf6eff1f5e8f4dcf9e4fdf1ecf0f9b2fff3f1">[email protected]</a>" }
if (user) {
return user
} else {
return null
}
}
})
]
...
PS: The name option may also be unnecessary when using a custom sign up page. It would be helpful to have the ability to exclude that as well...