TanStackT
TanStack3y ago
3 replies
faint-white

Authentication / Router question

Hi all, I'm new to Tanstack router and had some questions around setting up auth/nonAuth routes. I saw the post Tanner made in his docs regarding auth routing and I'm trying to get that to work but it doesn't seem to be.

I split up my routes so root has Auth and NonAuth, where both of those have all non authenticated routes and authenticated routes. I want it so if the user goes to the root domain "/" without specifying a path it will route them to /dashboard if they're authenticated and /login if they are not. Also, if they are not authenticated and go to /dashboard or authenticated routes it should route them back to login, and if they are authenticated and try to go to /login or nonauthenticated routes it should route them to dashboard.

Currently my code in the beforeLoad "to" value throws an error:TS2322: Type  "/login"  is not assignable to type  "/
it looks like it only allows / for some reason

here is my code: https://ctxt.io/2/AAAw9pIHFQ
Was this page helpful?