Is it possible to redirect post requests in wasp

Since there's no way to run code directly within Wasp upon signup or login, I've been trying to get around that while still keeping Wasp code untouched. I've created some custom code that I want to run on signup and I have it running on http://localhost:3002/auth/username/login. Wasp runs on port 3001 so usually the wasp request to that same endpoint would be at this link: http://localhost:3001/auth/username/login. When the post request is made to this link: http://localhost:3001/auth/username/login in Wasp the signup code is run to create a new user in Prisma. The code running on port 3002 that I created does the same thing with some extra steps. I want to be able to redirect any traffic that goes to this endpoint: http://localhost:3001/auth/username/login. to this endpoint: http://localhost:3002/auth/username/login. I've tried using Nginx to do the redirection but I don't think that'll work since for it to work Nginx would need to be listening on port 3001 and Wasp is using port 3001 so that would be a conflict. So is there some way I can redirect this traffic, without altering the Wasp code directly.
4 Replies
Filip
Filip8mo ago
Hey, @rithvik12345678. You're right - only a single process can run on a TCP port. If you're running the Wasp server process on 3001, everything needs to go through it first. I'll look into what we can do and get back to you.
martinsos
martinsos8mo ago
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! In the meantime, if you want to run something after signup, you can do your own custom logic by followin ginstructions here: https://wasp-lang.dev/docs/auth/username-and-pass#2-creating-your-custom-sign-up-action . It means you need to implement your own Auth UI component, and also your own signup action. For signup action, code example is in docs that should help quite a bit, and for AUth UI compennt, best bet is probably to check in the genereated code what it looks like and posisbly using parts of that. This way you can do custom logic before or after signup. As for custom logic after login -> what you can do is have your own Login page and then call login action on your own from there, and then you can also execute something upon successful login, check it out here: https://wasp-lang.dev/docs/auth/username-and-pass#1-using-the-signup-and-login-actions
rithvik12345678
rithvik123456788mo ago
@martinsos How soon do you think y'all will release the hooks Because the whole process of creating my own custom Auth UI is kind of cumbersome because there's a lot of things that happen automatically in the wasp source code that are hard for me to replicate.
martinsos
martinsos8mo ago
Ah yes I know, would be much nicer to have hooks! They are in our plan for the next bigger release, meaning they are at the top of the list of the stuff we are handling, but there is quite some stuff alongside them we are also working on, so it will probably take a 1 - 2 months to get it out.
Want results from more Discord servers?
Add your server