Route Guarding with nextjs
How do you implement route guarding with nextjs? Not too sure what would be the recommended way to do it. Basically what I is use a context provider then “useeffect“ my way into route guarding
Context: Firebase for backend and auth
6 Replies
middleware or something like get server side props
Can you show me a minimal example?
I did it with getServerSideProps as well, will send in an example asap
Dunno if that's the right way to do it
But it works
Thanks for sharing!
Where should I put this?
Also does it route guard any of the possible paths?
Ex: say I have path /A, /B, /Login. My expectations would be that if you go to /A or /B you get redirected to /Login and also if you go to /doesnotexist you also get redirected to /Login
Same file as the Page Components you create
Just like you do it all the time with getServerSideProps