From 3281bd42f9fcf1e55b769c4f0ecd6e9ac790a046 Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Thu, 20 Jun 2024 19:42:38 -0500 Subject: [PATCH] Improve sign-in error handling --- src/auth/actions.ts | 5 ++++- src/auth/index.ts | 2 ++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/auth/actions.ts b/src/auth/actions.ts index 477ee0b5..e4adb5a4 100644 --- a/src/auth/actions.ts +++ b/src/auth/actions.ts @@ -2,6 +2,7 @@ import { KEY_CALLBACK_URL, + KEY_CREDENTIALS_CALLBACK_ROUTE_ERROR_URL, KEY_CREDENTIALS_SIGN_IN_ERROR, KEY_CREDENTIALS_SIGN_IN_ERROR_URL, auth, @@ -21,7 +22,9 @@ export const signInAction = async ( } catch (error) { if ( `${error}`.includes(KEY_CREDENTIALS_SIGN_IN_ERROR) || - `${error}`.includes(KEY_CREDENTIALS_SIGN_IN_ERROR_URL) + `${error}`.includes(KEY_CREDENTIALS_SIGN_IN_ERROR_URL) || + // New error thrown in next-auth 5.0.0-beta.19 for incorrect credentials + `${error}`.includes(KEY_CREDENTIALS_CALLBACK_ROUTE_ERROR_URL) ) { // Return credentials error to display on sign-in page. return KEY_CREDENTIALS_SIGN_IN_ERROR; diff --git a/src/auth/index.ts b/src/auth/index.ts index da7e9c6e..9dab1b80 100644 --- a/src/auth/index.ts +++ b/src/auth/index.ts @@ -5,6 +5,8 @@ import Credentials from 'next-auth/providers/credentials'; export const KEY_CREDENTIALS_SIGN_IN_ERROR = 'CredentialsSignin'; export const KEY_CREDENTIALS_SIGN_IN_ERROR_URL = 'https://errors.authjs.dev#credentialssignin'; +export const KEY_CREDENTIALS_CALLBACK_ROUTE_ERROR_URL = + 'https://errors.authjs.dev#callbackrouteerror'; export const KEY_CALLBACK_URL = 'callbackUrl'; export const {