S
SolidJS9mo ago
Nimra

RouteGuard with FileRoutes

How can I add a routeGuard that allows every page to be protected except few routes like '/login'? I would like to maintain file based routing without having to manually add every route. Thanks!
4 Replies
apollo79
apollo799mo ago
Authjs has an example of how to achieve that... I think I would use something like this: https://authjs.dev/reference/solidstart/protected#when-using-csr And then you can switch protectedRoutes against unprotectedRoutes
Protected | Auth.js
When Using SSR
Nimra
Nimra9mo ago
Hey @apollo79 ! I checked this out already and got more confused how solid-start is structured. Why do I need to have protectedRoutes in my server code? Am I still using SSR even when it's off? I started a bug issue on github about this just a bit ago For now, I could only switch to manually placing routes in RouteGuard vs unprotected
apollo79
apollo799mo ago
No, you are not using SSR when it is off, but your server will serve the page in CSR mode. I thought you were using SSR and I like using a middleware more than wrapping every route in Protected, and, as stated below the example:
Note: the CSR method should also work when using SSR, the SSR method shouldn't work when using CSR
But I don't know exactly how Solid-Start is structured and it is a bit... interesting, that this works in CSR mode tbh
Nimra
Nimra9mo ago
Interesting that CSR is still being pushed by a server Maybe this is why my client libraries fail to compile on CSR mode as they still cant find node
Want results from more Discord servers?
Add your server
More Posts