Next-auth 5.0.0-beta.26 introduced a change that is causing a type error in AuthError
:
#12892
Unanswered
everspader
asked this question in
Help
Replies: 1 comment
-
I do not know the reason either, but it seems that AuthError has just been redesigned to get a clearer access to the error type, message and stack trace. With that, that is easier to change the sign-in title and message thrown by Auth.js on the sign-in action // Custom error class you can throw in your `auth.ts` file
export class UserSignInError extends CredentialsSignin {
// With that, we can also add more precised information to handle error cases
public readonly httpErrorCode: number
public constructor(httpErrorCode: number, message: string) {
super(message)
this.httpErrorCode = httpErrorCode
// This will overrides the error title instead of `CredentialsSignin` - and can be dynamic as a parameter too -
this.name = 'SignInError'
}
} On usage, } catch(error) {
if (error instanceof AuthError) {
switch (error.name) {
case 'CredentialsSignin':
return { error: 'Invalid credentials' }
case 'SignInError':
if (error instance of UserSignInError) {
// Here, we can now send clearer error code if we want
return { error: `User has failed to login, as the request returned HTTP ${error.httpErrorCode}` }
}
break
default:
return { error: 'Something went wrong' }
}
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
This commit introduced a change that makes the
type
property ofAuthError
an internal property, causing a type error when trying to access the type property in a situation like this:This change is not mentionded in the changelog here so I am wondering what is the purpose of such change?
Beta Was this translation helpful? Give feedback.
All reactions