custom signup action not running

I have followed the documentation from here: https://wasp-lang.dev/docs/auth/entities#custom-signup-action I am not able to get this custom sign up action to run upon sign up, it is still running the default one. Do I somehow need to change the function being called upon signup? I was under the impression having the name customSignup defined in wasp.main would mean it would override any default signup action. Any help would be appreciated, thanks!
Auth Entities | Wasp
Wasp supports multiple different authentication methods and for each method, we need to store different information about the user. For example, if you are using the Username & password authentication method, we need to store the user's username and password. On the other hand, if you are using the Email authentication method, you will need to s...
16 Replies
kapa.ai
kapa.ai5mo ago
Hi @Connor. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Yes, you're correct. Defining a customSignup action in your main.wasp file should override the default signup action. Here's how you can define it:
// main.wasp
action customSignup {
fn: import { signup } from "@src/auth/signup.js",
entities: [User]
}
// main.wasp
action customSignup {
fn: import { signup } from "@src/auth/signup.js",
entities: [User]
}
And here's an example of how your signup function in src/auth/signup.js could look like:
// src/auth/signup.js
import {
createProviderId,
sanitizeAndSerializeProviderData,
createUser,
} from 'wasp/server/auth'

export const signup = async (args, { entities: { User } }) => {
try {
const providerId = createProviderId('username', args.username)
const providerData = await sanitizeAndSerializeProviderData({
hashedPassword: args.password,
})

await createUser(
providerId,
providerData,
// Any additional data you want to store on the User entity
{},
)
} catch (e) {
return {
success: false,
message: e.message,
}
}

// Your custom code after sign-up.
// ...

return {
success: true,
message: 'User created successfully',
}
}
// src/auth/signup.js
import {
createProviderId,
sanitizeAndSerializeProviderData,
createUser,
} from 'wasp/server/auth'

export const signup = async (args, { entities: { User } }) => {
try {
const providerId = createProviderId('username', args.username)
const providerData = await sanitizeAndSerializeProviderData({
hashedPassword: args.password,
})

await createUser(
providerId,
providerData,
// Any additional data you want to store on the User entity
{},
)
} catch (e) {
return {
success: false,
message: e.message,
}
}

// Your custom code after sign-up.
// ...

return {
success: true,
message: 'User created successfully',
}
}
If you've done this and it's still not working, there might be an issue with your Wasp setup. Make sure you've followed all the steps in the Wasp documentation (https://wasp-lang.dev/docs/auth/entities#custom-signup-action) correctly. If the problem persists, it might be a good idea to reach out to the Wasp community or support for more specific help. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Connor, 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?
Connor
Connor5mo ago
This didn't work, do I need to specify a specific signup action to be run somehow? @kapa.ai
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you. One moment! :books: Sorry @Connor, 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?
Connor
Connor5mo ago
@Wasp Team @Wasp Expert Are you guys aware of any way to implement the custom sign up action? I follow the documentation and it is still running the default signup action. Do I need to specify the method I want instead anywhere else besides the action definition in main.wasp? Thanks for your help! Also this is the documentation link I am referring to: https://wasp-lang.dev/docs/auth/entities#custom-signup-action
Auth Entities | Wasp
Wasp supports multiple different authentication methods and for each method, we need to store different information about the user. For example, if you are using the Username & password authentication method, we need to store the user's username and password. On the other hand, if you are using the Email authentication method, you will need to s...
Vinny (@Wasp)
Vinny (@Wasp)4mo ago
Hey Connor. There's no need to tag anyone in this questions forum. The team will see them and get to them one-by-one when we can. For your custom sign-up function, if you could share your main.wasp file and your custom sign up function, that would help. Also try adding a console.log to your funtion and see what happens when you try to register a new user. btw @Connor what are you trying to achieve with your custom signup function? is it necessary? could you use custom signup fields instead? https://wasp-lang.dev/docs/auth/overview#1-defining-extra-fields ah. I think i see your issue now. If you're using a custom signup action then you have to call that action directly to register a user. Therefore, youll have to create your own custom sign up flow from scratch, I believe.
Connor
Connor4mo ago
Thanks for your response! I appreciate it! Ah that makes sense, how do I create that custom signup flow to call my custom action? Is there I spot I should put it under auth: {...} within main.wasp? I'm basically looking to do all the normal create user functionalities but also reach out to an external api and gather information from a url they provided on signup. I have modified the signup field to account for this new url field we are wanting on signup, but I just don't know how to link the custom signup action I have defined.
Vinny (@Wasp)
Vinny (@Wasp)4mo ago
instead of doing it on signup, why don't you add a property to the user, like isSignupComplete and default it to false. When a user logs in and accesses the home page, check if signup is complete, and if not, call the action:
import { useAuth } from 'wasp/client/auth'
import { customSignupAction } from 'wasp/client/operations'

export function HomePage() {
const { data: user } = useAuth()

if (user.isSignupComplete === false) {
await customSignupAction(user);
}

// ...
}
import { useAuth } from 'wasp/client/auth'
import { customSignupAction } from 'wasp/client/operations'

export function HomePage() {
const { data: user } = useAuth()

if (user.isSignupComplete === false) {
await customSignupAction(user);
}

// ...
}
Connor
Connor4mo ago
Yeah good idea, I will probably just do that then. I just wasn’t sure if there was a clean way to customize signup but it sounds like this idea would work perfect. Thank you! Also, I didn’t realize the wasp compiler was in Haskell, that’s awesome! It’s a really cool language
Vinny (@Wasp)
Vinny (@Wasp)4mo ago
yeah, because Wasp is taking care of so much for you, this is probbaly the cleaner/easier way to do it in the end. @martinsos will be happy to hear that 🙂
martinsos
martinsos4mo ago
Thanks @Connor, indeed both compiler and the wasp CLI are implemented in Haskell! We don't out it much around though, as sometimes people think that means that they need to know Haskell to use Wasp (which they don't). But Haskell is perfect for use cases like this, we are having a great time using it.
miho
miho4mo ago
What @Vinny (@Wasp) said seems like the best option if you don't want to go with a 100% custom signup flow 👍 Going custom means going custom for everything. Then you are writing your custom React components and your custom actions. This is a really extreme case where would need this. But sometimes you really need to. That's why we are implementing auth hooks (coming soon) that would hopefully enable you even more without the need of going full custom.
martinsos
martinsos4mo ago
Would Auth Hooks solve the situation here @miho ?
miho
miho4mo ago
Yep, signup auth hook would make this possible 👍
martinsos
martinsos4mo ago
Ok, so @Connor this is improtant for you then -> in a couple of weeks we will be releasing new version of Wasp that will bring Auth Hooks, which will allow you to execute custom login e.g. upon signup. This should be a good solution for your situation here.
Connor
Connor4mo ago
Awesome, I'll have to keep an eye out for the new version but will just work with the suggested solution in the meantime. Thanks for all your guys help! And I think Haskell is a great use case for a compiler like Wasp! Really any function language has the advantage of pattern matching which is so convenient for building a CFG and AST but that's just my opinion lol
martinsos
martinsos4mo ago
Oh you are 100% right! Haskell has awesome type system, so for me it is the best language for any use case where you can get by with garbage collected language (don't need low level performance control). It has its quirks, and it is scary at first, but it is awesome once you get into it, it spoiled other language for me. And its ADTs (basically ability to write something like data Expression = Add Expr Expr | Abs Expr | Const Int), even though a quite simple feature, are such an enabler for me, that I really miss them in other languages (Rust has them though!). Ah Haskell :D. If only it was used more and it had stronger ecosystem, that would be just awesome. It is not that ecosystem is bad, it is actually quite rich taking into regard it is not super popular, and there are awesome libraries, especially for stuff like compilers and parsing, but when you compare it to ecosystems of JS or Rust, there is so much more happening there. Whoops now you got me into Haskell rant heh
Want results from more Discord servers?
Add your server