Catching error when creating a user
I am building an intranet as a fun project on the side. For the login flow, i want to use oauth providers, but only allow for users with email existing in a table in convex. I am able to this in the createOrUpdate callback. However, in the instance where someone is trying to login that i dont want to allow, an error is thrown. The error does however only show in the convex logs. Is there a way I can catch this error so i can show an appropriate message on the client?
10 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
The way to throw errors that make it back to the client side is to use ConvexError https://docs.convex.dev/functions/error-handling/application-errors
Application Errors | Convex Developer Hub
If you have expected ways your functions might fail, you can either return
This don't seem to work though. When I am throwing ConvexError within the createOrUpdate callback, the error dont propagate back to the user.
Oh interesting, sorry for the bad suggestion.
Huh, how do these show up in the convex dashboard logs?
Here you go 🙂
Hmm I can't find anywhere in the convex auth source where the error would be caught. Can you share any of the code around your
signIn()
call? Any chance there are try/catch blocks or error boundaries? Othewise, what does the user see when the error is thrown?Yeah @Gnomis what do you see in the browser console in dev, nothing?
Nothing shows up in the browser console in dev. For the user, it simply looks like nothing happens when you click the button except that the page loads in again. As far as where the errors should be caught, I don't do any try/catch calls as I want to actually get the error. I am simply using the signin from useauthaction hook.
The ideal interface here would be the signIn call erroring, yeah? and the problem is that signIn returns succesfully? What about the network tab, is there nothing indicating the failure? Makes sense this should be changed if so, would you file a new issue or add on to https://github.com/get-convex/convex-auth/issues/124? I thought we could throw errors and get them back here but apparently not, sounds like this requires some restructuring if all this happens in the background.
GitHub
Cleanly handling expected errors with Password provider · Issue #12...
There are a couple of posts on the discord about this but doesn't seem to be any answer. In short, it's really unclear how to properly handle expected (application) errors. These types of e...
Filed a new issue here: https://github.com/get-convex/convex-auth/issues/165. Thanks for all the help!
GitHub
Issues · get-convex/convex-auth
Library for built-in auth. Contribute to get-convex/convex-auth development by creating an account on GitHub.