couldn't handle custom error from authorize in frontend, using Vite, React and Hono.js #12495
-
Environmentnode version: v20.13.1
Reproduction URLhttps://github.com/QingjiaTsang/reproduce-authjs-issue Describe the issueI have followed the docs guide, but failed. In honojs auth config file, I tried to throw a custom error from authorize:
But it failed to catch that in frontend:
It always prints like this, no matter how I tried the solutions relative to this issue in the github (like creating a custom Error class extended from CredentialsSignin or AuthError), it always can't bring the custom error message out. So I guess those solutions there maybe only work for nextjs, and I'm using vite, React and Honojs, it doesn't have the server side like server action in nextjs. How to reproduce
Expected behaviorhave an easy access to handle the custom error thrown from authorize in frontend |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Here for someone using pure React and coming up with the same problem: I write my own sign-in endpoint for handling the custom error which is not so supported by authjs when it comes to just use React instead of Nextjs.
|
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
Here for someone using pure React and coming up with the same problem:
I write my own sign-in endpoint for handling the custom error which is not so supported by authjs when it comes to just use React instead of Nextjs.
Check out the code below. This is mainly what the endpoint handler does, and it basically just verifies the user and inserts the session to the db by ourselves. Maybe you would wonder how it works; it's pretty easy. Just check out the network section in the devtools, you'll see the auth.js always sending requests to /api/auth/session to see if we signed in. Under the hood, it just queries the db to verify the seesion. You can go deep into the source code of authjs to check…