T
TanStack6mo ago
unwilling-turquoise

Authentication using React context/hooks

how do i adapt this https://tanstack.com/router/latest/docs/framework/react/guide/authenticated-routes#authentication-using-react-contexthooks to work with start, specifically with convex auth. i have changed _root.tsx and router.tsx but i have no App.tsx to modify and inject the context.
Authenticated 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 th...
11 Replies
unwilling-turquoise
unwilling-turquoiseOP6mo ago
extended-salmon
extended-salmon5mo ago
hey @snoww I've the same issue, did you figure it out?
fascinating-indigo
fascinating-indigo5mo ago
You could just pop the provider in the root route as seen the in the Clerk example here https://clerk.com/docs/quickstarts/tanstack-react-start#add-clerk-provider-to-your-app
unwilling-turquoise
unwilling-turquoiseOP5mo ago
that doesn't let you acces the data in the loader since loaders don't have access to react hooks no i did not, i moved to plain old router since most of the server logic was on convex anyways
xenial-black
xenial-black5mo ago
Hi @snoww , I face the same issue. Did you completely quit tanstack start or did you manage to use the classic router in tanstack start ? How did you do ?
unwilling-turquoise
unwilling-turquoiseOP5mo ago
yeah i completly quit start and ssr i'll probably check it out again when vinxi is gone
equal-aqua
equal-aqua4mo ago
Hey jumping in here what is the exact issue you are experiencing as I’m not sure how vinxi plays in here? I’ve been able to set up with intermediary components and layouts no issue, happy to help here if I can! Set up multiple diff auth providers*
unwilling-turquoise
unwilling-turquoiseOP4mo ago
looking back i don't actually see why i thought vinxi was the problem the real problem is that <StartClient> does not have a context prop like <RouterProvider> or maybe the context should be injected somewhere else, but StartClient seems like a natural place for me the auth works, you just don't get it as global context so you can access it in loaders
helpful-purple
helpful-purple4mo ago
GitHub
GitHub - juliusmarminge/convex-betterauth
Contribute to juliusmarminge/convex-betterauth development by creating an account on GitHub.
unwilling-turquoise
unwilling-turquoiseOP3mo ago
this looks like running betterauth on convex's backend convex auth is a seperate product https://labs.convex.dev/auth the issue is that they only expose a react hook to get auth status
Convex Auth - Convex Auth
Authentication library for your Convex backend
helpful-purple
helpful-purple3mo ago
There’s an issue open on their GitHub https://github.com/get-convex/convex-auth/issues/126
GitHub
Support for TanStack Start · Issue #126 · get-convex/convex-auth
People in the Convex Discord have been trying this lately, I think it&#39;s going to require adding some code in this library to do it nicely, similar to Next.js middleware. Filing for tracking, ET...

Did you find this page helpful?