W
Wasp•2mo ago
switchcom

Is there a way to redirect a user after successful auth to a dynamically defined URL?

Instead of static onAuthSucceededRedirectTo, I'd like to move the user to say something like /profile/<UUID>/settings . Should I use a server redirect instead?
2 Replies
kapa.ai
kapa.ai•2mo ago
Hi @switchcom. 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 provided knowledge sources, there isn't currently a built-in way in Wasp to redirect a user to a dynamically defined URL after successful authentication. The onAuthSucceededRedirectTo option only supports static URLs. However, there are a few potential workarounds you could consider: 1. Custom Auth UI: You could implement your own custom authentication UI and logic, which would allow you to handle the redirection manually after a successful login. This is mentioned in the Auth documentation (https://wasp-lang.dev/docs/auth/username-and-pass#1-using-the-signup-and-login-actions). 2. Use localStorage: As suggested in a Discord conversation, you could use localStorage to store the desired redirect URL before authentication and then manually redirect the user after a successful login by checking the user object from useAuth hook. 3. Server-side redirect: Your suggestion of using a server redirect could be a viable option, but it would require implementing custom logic on the server-side. It's worth noting that there's an open GitHub issue (#1772 (https://github.com/wasp-lang/wasp/issues/1772)) to improve "seamless" login redirects, which might address this functionality in the future. For now, the most straightforward approach would be to implement your own custom authentication flow, which would give you full control over the redirection process. However, this would require more work on your part and might not leverage all of Wasp's built-in authentication features. If you need a more immediate solution without extensive customization, you might want to consider using a combination of localStorage and client-side redirection after checking the authentication state. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @switchcom, 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?
miho
miho•2mo ago
Unfortunately, Wasp doesn't support server-side redirect since it's a regular SPA client + regular server (the client is not rendered by the server) so all the redirects need to happen on the client. If you set onAuthSucceededRedirectTo to some page that has redirect logic based on the user you get from useAuth it should be the solution you are looking for 🙂

Did you find this page helpful?