Redirecting unauthenticated users? Convex Auth + TanStack Router
Hi! Hopefully this is an easy one, but I'm new to both Convex, TanStack, and this is my first time ever setting up authentication! So trying to follow best pratices and reading but getting a little lost.
I have a
/settings
route and I want to redirect unauthenticated users away to /signin
. I found the docs in TanStack Router for how to set up a redirect on beforeLoad
but I don't know how to check for isAuthenticated()
using Convex Auth. Help?
https://tanstack.com/router/latest/docs/framework/react/guide/authenticated-routes#redirectingAuthenticated Routes | TanStack Router React Docs
Authentication is an extremely common requirement for web applications. In this guide, we'll walk through how to use TanStack Router to build protected routes, and how to redirect users to login if they try to access them.
The route.beforeLoad Option
3 Replies
Would love to see a best-practice example of managing authentication and loading state for a page
Ah, I was able to get this set up.
In
main.tsx
:
In routes/__root.tsx
:
On routes/settings.tsx
:
Thanks for sharing this @Eva! This is helpful for providing instructions about this, which hopefully get up this week.
Awesome! Convex Auth (and Convex generally) have been amazing so far. Was able to set up magic links without any prior knowledge of auth 🤩