W
Wasp-lang3mo ago
KC

Should the `/login` route respect the `onAuthSucceededRedirectTo` when the user visits `/login`?

When the user first logs in from the login route, they are redirected to the path set in onAuthSucceededRedirectTo. However, when the user is already logged in and visits the login route path /login, they are redirected to /. I am using email auth if that helps.
6 Replies
kapa.ai
kapa.ai3mo ago
Hi @KC (GitHub @Case-E). I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- The onAuthSucceededRedirectTo field in the Wasp configuration is used to specify the route to which Wasp will redirect a user after a successful login/signup. The default value for this field is / source (https://wasp-lang.dev/docs/auth/overview#onauthsucceededredirectto-string). However, if you want to redirect the user to a different route when they visit /login while already logged in, you might need to implement a custom logic in your application. One possible workaround suggested by the Wasp community is to use localStorage to keep some user info and manually redirect to /login by checking the user you get from useAuth source (https://discord.com/channels/686873244791210014/1223231374060949555). There is also an open issue on GitHub to improve the "seamless" login redirects in Wasp source (https://github.com/wasp-lang/wasp/issues/1772). You might want to follow this issue for updates on this feature. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @KC (GitHub @Case-E), 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?
martinsos
martinsos3mo ago
Oh that is interesting, might be a bug on our side! Would you mind opening an issue for this on github @KC (GitHub @Case-E) ?
KC
KC3mo ago
Thanks @martinsos created an issue here: https://github.com/wasp-lang/wasp/issues/2101
GitHub
onAuthSucceededRedirectTo value isn't respected when the user visit...
Describe the bug When the user first logs in (tested email auth), the user is redirected to the value set in onAuthSucceededRedirectTo or the default / if nothing is set. However, once successfully...
martinsos
martinsos3mo ago
Awesome, thanks!
KC
KC3mo ago
For anyone else who stumbles across this. If a user visits the /login route, React will just render that page, you may want to add the following in your login route code: import { useEffect } from "react"; import { useAuth, LoginForm } from "wasp/client/auth"; import { useHistory } from "react-router-dom"; // In the function: const history = useHistory(); const { data: user } = useAuth(); useEffect(() => { if (user) { history.push("/app/dashboard"); } }, [user, history]);
martinsos
martinsos3mo ago
That's a nice workaround!
Want results from more Discord servers?
Add your server