W
Wasp-lang•3mo ago
Wlski

redirect from landing page to another if user is logged in?

trying to do exactly what the title says. any advice would be nice
2 Replies
kapa.ai
kapa.ai•3mo ago
Hi @Wlski. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Sure, you can achieve this by using the useAuth hook provided by Wasp. This hook allows you to check if a user is logged in and then perform a redirect based on the user's authentication status. Here's a basic example of how you can use it:
import { useAuth } from 'wasp/client/auth'
import { Redirect } from 'react-router-dom'

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

if (user) {
return <Redirect to="/your-desired-page" />
}

// ...
}
import { useAuth } from 'wasp/client/auth'
import { Redirect } from 'react-router-dom'

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

if (user) {
return <Redirect to="/your-desired-page" />
}

// ...
}
In this example, when the HomePage component is loaded, it checks if a user is logged in. If a user is logged in (user is not null), it redirects to "/your-desired-page". If no user is logged in, it continues to render the rest of the HomePage component. You can replace "/your-desired-page" with the path to the page you want to redirect logged-in users to. For more information, you can refer to the following sources: - useAuth hook and Redirect example (https://wasp-lang.dev/docs/auth/social-auth/overview#3-showing-the-correct-state-on-the-client) - useAuth hook documentation (https://wasp-lang.dev/docs/auth/overview#on-the-client) - Protecting a page with authRequired (https://wasp-lang.dev/docs/auth/overview#protecting-a-page-with-authrequired) ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @Wlski, 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?
Filip
Filip•2mo ago
Hey @Wlski, the bot gave the right answer. Let me know if you need anything else here 🙂
Want results from more Discord servers?
Add your server