Traditional credentials authentication
A username-and-password login backed by an existing application API.
Auth.js · Type Alias
CredentialsConfig defines the options for Auth.js’s Credentials provider. It specifies sign-in inputs and custom authorization behavior, with authorize returning a User on success or null on failure.
CredentialsConfig describes the configuration accepted by Auth.js’s Credentials provider. It lets you define the credential inputs and an authorize callback that handles the submitted request and returns either a User for success or null for failure.
type CredentialsConfig<CredentialsInputs extends Record<string, CredentialInput>> = CommonProviderOptions & { credentials: CredentialsInputs; authorize: (credentials: Partial<Record<keyof CredentialsInputs, unknown>>, request: Request) => Awaitable<null | User>; }| Name | Type | Description |
|---|---|---|
config | Partial<CredentialsConfig<CredentialsInputs>> | Configuration options for the Credentials provider, including credential input definitions and authorization logic. |
credentials | CredentialsInputs | Definitions for the credential fields exposed by the provider and default sign-in form. |
credentials | Partial<Record<keyof CredentialsInputs, unknown>> | Submitted credential values. |
request | Request | The original authentication request. |
CredentialsConfig<CredentialsInputs> configures the Credentials provider; authorize returns Awaitable<null | User>.
import Credentials from "next-auth/providers/credentials"
Credentials({
credentials: {
username: { label: "Username" },
password: { label: "Password", type: "password" },
},
async authorize({ request }) {
const response = await fetch(request)
if (!response.ok) return null
return (await response.json()) ?? null
},
})This config defines the sign-in fields and forwards the request to an authentication service; a successful response must provide a User.
A username-and-password login backed by an existing application API.
A login requiring several custom fields rather than OAuth.
Authentication through a domain-specific or hardware-backed credential flow.
CredentialsConfig configures the Credentials provider. Its credentials property describes the form inputs, while authorize receives the submitted credentials and request and returns Awaitable<null | User>.
Follow-up: What indicates failed authentication? Returning null from authorize; a successful login must return a User object.
The credentials map determines the available input keys and the fields rendered by the default sign-in page. Its keys are typed through CredentialsInputs, providing type safety inside authorize.
Follow-up: Why does the input definition affect authorize? The same keys determine the Partial<Record<keyof CredentialsInputs, unknown>> shape passed to the callback.
authorize gets the submitted credentials and original Request, giving full control over custom authentication handling. It may perform asynchronous work because its return type is Awaitable.
Follow-up: What should an implementation do when an upstream authentication request fails? Return null rather than a User.
CredentialsCredentialsInputsCredentialInputUserProvider