You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/pages/getting-started/authentication/credentials.mdx
+58-1Lines changed: 58 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -35,7 +35,53 @@ so there are no plans to remove this provider.
35
35
36
36
### Credentials Provider
37
37
38
-
First, let's initialize the `Credentials` provider in the Auth.js configuration file. You'll have to import the provider and add it to your `providers` array.
38
+
To use the `Credentials Provider`, you’ll first need to import and configure it in your `Auth.js` setup. This provider allows you to implement custom login logic based on form input values.
39
+
40
+
Here’s how to set it up:
41
+
42
+
1.Importtheprovider.
43
+
2. Add it to the `providers` array in your `Auth.js` config.
44
+
3. Define the `credentials` and `authorize` fields.
45
+
46
+
#### `credentials`
47
+
48
+
The `credentials` object defines the input fields displayed on the default sign-in page. These inputs are automatically rendered on the route:
49
+
50
+
-`/api/auth/signin` (Next.js)
51
+
-`/auth/signin` (Other frameworks)
52
+
53
+
Each field accepts the following properties:
54
+
55
+
-`label`: Input label
56
+
-`type`: HTML input type (`text`, `password`, etc.)
57
+
-`placeholder`: Placeholder text
58
+
59
+
> These fields are also passed to the `authorize` function under the `credentials` argument.
60
+
61
+
For more details, see the [Built-in Pages guide](https://authjs.dev/guides/pages/built-in-pages).
62
+
63
+
```ts
64
+
Credentials({
65
+
credentials: {
66
+
email: {
67
+
type: "email",
68
+
label: "Email",
69
+
placeholder: "johndoe@gmail.com",
70
+
},
71
+
password: {
72
+
type: "password",
73
+
label: "Password",
74
+
placeholder: "*****",
75
+
},
76
+
},
77
+
})
78
+
```
79
+
80
+
#### `authorize`
81
+
82
+
The `authorize` function handles the custom login logic and determines whether the credentials provided are valid.
83
+
84
+
It receives the input values defined in `credentials`, and you must return either a user object or `null`. If `null` is returned, the login fails.
When authorize returns null, Auth.js handles the error in one of two ways:
594
+
595
+
Using built-in pages:
596
+
597
+
- The user is redirected to the login page with the query string: `?error=CredentialsSignin&code=credentials`. You can customize the code using the [credentials provider options](https://authjs.dev/reference/core/providers/credentials#returns).
598
+
- Using form actions or custom error handling (e.g., in Remix, SvelteKit): The error is thrown as credentialssignin and must be caught manually in your server action. See more in the [Auth.js error reference](https://authjs.dev/reference/core/errors#credentialssignin).
0 commit comments