I have a idea to fix the next-auth error when you return null in the authorize
function in the next-auth v5@beta version (error: [auth][error] CallbackRouteError: Read more at https://errors.authjs.dev#callbackrouteerror [auth][cause]: Error ,at Module.callback ))
#11684
Replies: 2 comments 5 replies
-
So even if we do this, it will return a 200 in the server action which calls, for example in my case, the await signin method. So when the client component returns, I'll get a success alert when I normally wouldn't. How can I manage this? I don't really have any ideas at the moment apart from making 2 call api. One before the signin method which will check if the credentials are ok and then I redo one in nextAuth. Yes, I'm calling a remote api. |
Beta Was this translation helpful? Give feedback.
-
i try this and this not working , user just login and create a token instead return error to client |
Beta Was this translation helpful? Give feedback.
-
Goals
1.to let user can customise the signIn details of the authorize functions not to directly stupidly thow the error
2.
3.
Non-Goals
Background
as when I use the next-auth@beta to customise the signIn actions with the functions of the
authorize
,just like below to return null ,which stands login failed or credentails invalid, it will directly throw an error like below:next-auth version: "next-auth": "^5.0.0-beta.20"
and also I have found the source code from the path(node_modules/@auth/core/lib/actions/callback/index.js ) where throw the error above , as we can see the details is here below:
and also as we can see the class of the
CredentialsSignin
just inherited from the Error classbut as we can see the callback functions already included the
try...... catch.......
logicals , here below in the souce code,so in my opptions , there was totally
stupid
andredundant
to thow this customise class (CredentialsSignin ),even thougth the coder know the user credentials' valid or not, and know how to handle the invalid credentails return, otherwise, you team still want keep thow thisstupid
andredundant
customised class (CredentialsSignin ) , we should add a statement to judge the user object that the functionauthorize
return is empty or not, I mean the( user==null? thow new CredentialsSignin : (Object.keys(user).length ==0 ? do nothing: let the user login ))
Proposal
yes, to fix the error above , I think there should be two solutions here below:
solutuions 1
: commented or remove thethrow new CredentialsSignin();
from the souce codenode_modules/@auth/core/lib/actions/callback/index.js
when theuser == null
, which is totallly redundant, because the callback functions already include thetry....catch ......
logicaljust like here below:
and also , the coder can cutomised the
authorize
functions as they likes, just like here below:solutions 2
: also you can keep thestupid
andredundant
class throw CredentialsSignin(); and just change the in the souce ( from the souce codenode_modules/@auth/core/lib/actions/callback/index.js
) like here below:so that when the coder use the authorize functions just like here below:
Beta Was this translation helpful? Give feedback.
All reactions