Can't get protected routes to work
I'm not sure what I'm doing wrong her but I cannot seem to figure out how I can create a protected route.
I'm tryint to make a protected route
/authenticated/dashboard
. but no matter what does_authenticated.tsx
not get triggered and redirect the client to /login ?
18 Replies
other-emerald•17mo ago
either you need to rename
_authenticated.tsx
to authenticated.tsx
(remove the leading underscore) or rename the folder authenticated
to _authenticated
(add a leading underscore)
the second option would result in the path to just be /dashboard
(without the authenticated
part)absent-sapphireOP•17mo ago
Thank you SOOOOOO MUCH!
I've bee trying to figure out where I was going wrong for some time now.
Can I ask what you personally would prefer? or no
underscore or no underscore
other-emerald•17mo ago
this is not a matter of preference, but rather how the url should look like
absent-sapphireOP•17mo ago
Fair point.
One thing I don't get thought. TS is complaining and only know about the routes
/
/login
/about
, but it doesn't recognize /authenticated
Argument of type '"/authenticated"' is not assignable to parameter of type 'keyof FileRoutesByPath'.
other-emerald•17mo ago
how does your file/folder structure look like now?
do you use the router vite plugin? is vite running?
absent-sapphireOP•17mo ago
other-emerald•17mo ago
i.e. did the generator run
absent-sapphireOP•17mo ago
yes and yes 🙂
other-emerald•17mo ago
would need a reproducer, e.g. by forking one of the existing example on stackblitz
or this as a git repo
absent-sapphireOP•17mo ago
I think the easiest way would be to give you the repo 🙂
https://github.com/Notaduck/fitter-fullstack/tree/feature/frontend
other-emerald•17mo ago
private repo? cannot access
absent-sapphireOP•17mo ago
2 sec.
It shoulde be public by now.
And thank you so much for the help so far!
other-emerald•17mo ago
where should I be seeing this error?
absent-sapphireOP•17mo ago
I'm so sorry! I really don't know why there was a delay, I tried to restart the TS server in vs-code, restart the application but for some was there a delay with updating
routeTree.gen.ts
other-emerald•17mo ago
so error has vanished?
absent-sapphireOP•17mo ago
Si, it just took a minute or two before routeTree.gen.ts was updated and typescript could see the routes -_"
other-emerald•17mo ago
shouldn't take that long, but well ...
absent-sapphireOP•17mo ago
Nope. and my laptop isn't THAT old, not new but not that old thoug.