Protected Routes Implementation #92
-
Hi @tannerlinsley, love the whole tanstack, react-location looks great as well, I just want some help with how can we implement protected routes in react-location, that's the only thing to figure out before I can use it in my upcoming project |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments 22 replies
-
I tried two ways:
[
{
path: '/',
element: <Auth><Home /></Auth />
}
]
[
{
path: '/',
element: <Auth />
children: [
{
path: '/',
element: <Home />
}
]
}
] I also wanted to know if there is a better way to do it. |
Beta Was this translation helpful? Give feedback.
-
Hello I'm willing to validate a security |
Beta Was this translation helpful? Give feedback.
-
Thanks!
or
where Then in the routes:
and for
It is worth mentioning that both approaches will trigger the
|
Beta Was this translation helpful? Give feedback.
-
I've added a new documentation page to gather the official recommendations: https://tanstack.com/router/v1/docs/guide/authenticated-routes To hit on a few other points:
|
Beta Was this translation helpful? Give feedback.
-
Thank you! |
Beta Was this translation helpful? Give feedback.
-
You can actually get the auth zero context from within a wrapper component higher up from your router provider, then pass that information into the router context via the context prop on the router provider.
…On Aug 9, 2023 at 12:43 AM -0400, calloc134 ***@***.***>, wrote:
Is it possible to use the hook of react inside the beforeLoad function?
I need to get state and execute that function from a hook like useAuth0.
import { useAuth0 } from ***@***.***/auth0-react';
// ...
beforeLoad: async () => {
const { isAuthenticated, loginWithRedirect } = useAuth0();
if (!isAuthenticated) {
loginWithRedirect({ redirectUri: '/protected' });
throw new Error('Redirecting to login');
}
},
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
The protected route does not redirect user when not logged.
|
Beta Was this translation helpful? Give feedback.
-
how to separate two stack ,for example log in stack and logged in stack how to implement this please provide a solution i need your help |
Beta Was this translation helpful? Give feedback.
-
Someone has an sugestion for file based router for this common problem? |
Beta Was this translation helpful? Give feedback.
I've added a new documentation page to gather the official recommendations: https://tanstack.com/router/v1/docs/guide/authenticated-routes
To hit on a few other points: