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
@@ -188,11 +188,25 @@ export class InvalidCallbackUrl extends AuthError {
188
188
}
189
189
190
190
/**
191
-
* The `authorize` callback returned `null` in the [Credentials provider](https://authjs.dev/getting-started/providers/credentials-tutorial).
192
-
* We don't recommend providing information about which part of the credentials were wrong, as it might be abused by malicious hackers.
191
+
* Can be thrown from the `authorize` callback of the Credentials provider.
192
+
* When an error occurs during the `authorize` callback, two things can happen:
193
+
* 1. The user is redirected to the signin page, with `error=CredentialsSignin&code=credentials` in the URL. `code` is configurable.
194
+
* 2. If you throw this error in a framework that handles form actions server-side, this error is thrown, instead of redirecting the user, so you'll need to handle.
193
195
*/
194
196
exportclassCredentialsSigninextendsSignInError{
195
197
statictype="CredentialsSignin"
198
+
/**
199
+
* The error code that is set in the `code` query parameter of the redirect URL.
200
+
*
201
+
*
202
+
* ⚠ NOTE: This property is going to be included in the URL, so make sure it does not hint at sensitive errors.
203
+
*
204
+
* The full error is always logged on the server, if you need to debug.
205
+
*
206
+
* Generally, we don't recommend hinting specifically if the user had either a wrong username or password specifically,
207
+
* try rather something like "Invalid credentials".
208
+
*/
209
+
code: string="credentials"
196
210
}
197
211
198
212
/**
@@ -433,6 +447,26 @@ export class MissingCSRF extends SignInError {
433
447
statictype="MissingCSRF"
434
448
}
435
449
450
+
constclientErrors=newSet<ErrorType>([
451
+
"CredentialsSignin",
452
+
"OAuthAccountNotLinked",
453
+
"OAuthCallbackError",
454
+
"AccessDenied",
455
+
"Verification",
456
+
"MissingCSRF",
457
+
"AccountNotLinked",
458
+
"WebAuthnVerificationError",
459
+
])
460
+
461
+
/**
462
+
* Used to only allow sending a certain subset of errors to the client.
463
+
* Errors are always logged on the server, but to prevent leaking sensitive information,
464
+
* only a subset of errors are sent to the client as-is.
465
+
*/
466
+
exportfunctionisClientError(error: Error): error is AuthError{
* by a popular library like [Zod](https://zod.dev)
30
30
* :::
31
31
*
32
+
* This method expects a `User` object to be returned for a successful login.
33
+
*
34
+
* If an `CredentialsSignin` is thrown or `null` is returned, two things can happen:
35
+
* 1. The user is redirected to the login page, with `error=CredentialsSignin&code=credentials` in the URL. `code` is configurable, see below.
36
+
* 2. If you throw this error in a framework that handles form actions server-side, this error is thrown by the login form action, so you'll need to handle it there.
37
+
*
38
+
* In case of 1., generally, we recommend not hinting if the user for example gave a wrong username or password specifically,
39
+
* try rather something like "invalid-credentials". Try to be as generic with client-side errors as possible.
40
+
*
41
+
* To customize the error code, you can create a custom error that extends {@link CredentialsSignin} and throw it in `authorize`.
42
+
*
43
+
* @example
44
+
* ```ts
45
+
* class CustomError extends CredentialsSignin {
46
+
* code = "custom_error"
47
+
* }
48
+
* // URL will contain `error=CredentialsSignin&code=custom_error`
49
+
* ```
50
+
*
32
51
* @example
33
52
* ```ts
34
-
* //...
35
-
* async authorize(credentials, request) {
53
+
* async authorize(credentials, request) { // you have access to the original request as well
0 commit comments