W
Wasp3d ago
ayo

onBeforeSignup not erroring out

How can I break out of the signup process when doing a onBeforeSignup and it returns an error I see this in the documentation
Wasp ignores the hooks' return values. The only exception is the onBeforeOAuthRedirect hook, whose return value affects the OAuth redirect URL.
https://wasp-lang.dev/docs/auth/auth-hooks#using-hooks
Auth Hooks | Wasp
Auth hooks allow you to "hook into" the auth process at various stages and run your custom code. For example, if you want to forbid certain emails from signing up, or if you wish to send a welcome email to the user after they sign up, auth hooks are the way to go.
3 Replies
kapa.ai
kapa.ai3d ago
Hi @ayo. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Based on the knowledge sources provided, it appears that Wasp currently does not have built-in support for breaking out of the signup process using onBeforeSignup hooks. The documentation you've cited is correct in stating that Wasp ignores the return values of most hooks, including onBeforeSignup. However, there are a couple of alternatives you could consider: 1. Custom Signup Action: Instead of using the default signup process, you can create a custom signup action. This allows you to implement your own logic, including error handling and breaking out of the process when needed. Wasp Docs: Creating your custom sign-up action provides an example of how to implement a custom signup action. In this approach, you can throw errors or return error messages as needed:
export const signup = async (args, _context) => {
try {
// Your custom signup logic here
// ...
} catch (e) {
return {
success: false,
message: e.message,
}
}
// ...
}

export const signup = async (args, _context) => {
try {
// Your custom signup logic here
// ...
} catch (e) {
return {
success: false,
message: e.message,
}
}
// ...
}

2. Future Hooks: The Wasp team is planning to add more flexible hooks in the future. As mentioned in a Discord conversation: Discord: Is it possible to redirect post requests in wasp states: "We will be adding hooks where you will be able to run code after/before signup/login, but yeah we don't have that yet unfortunately!" These future hooks may provide better support for breaking out of the signup process or handling errors during signup. For now, if you need fine-grained control over the signup process, including the ability to break out of it based on certain conditions, implementing a custom signup action is likely your best option. This approach allows you to handle errors and control the flow of the signup process more precisely. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @ayo, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
ayo
ayoOP3d ago
I'll give option 1 an attempt
Vinny (@Wasp)
Vinny (@Wasp)2d ago
What do you mean "break out of the signup process"? Can you share your onBeforeSignup code?

Did you find this page helpful?