Proper, reusable way to ensure that user is authenticated on specific routes? #2200
-
What is a proper, secure way, to ensure that user is authenticated on specific routes? Say I have /admin/ page, on which I require the user to be authenticated, before I execute the code in getServerSideProps, I want to ensure that the user is logged in. If the user is not logged in, I want to redirect to the login page, and after login, user will be redirected back. I can't find much documentation on this. I can implement my own workaround, but I expect there to be some default way of doing this, in the library. Any help is much appreciated |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 10 replies
-
https://next-auth.js.org/tutorials/securing-pages-and-api-routes Personally I don't like to use getServerSideProps for only auth, so I came up with this: https://next-auth.js.org/getting-started/client#custom-client-session-handling (I think we should move the latter into the former page) I hope it helps! 😊 |
Beta Was this translation helpful? Give feedback.
https://next-auth.js.org/tutorials/securing-pages-and-api-routes
Personally I don't like to use getServerSideProps for only auth, so I came up with this:
https://next-auth.js.org/getting-started/client#custom-client-session-handling
(I think we should move the latter into the former page)
I hope it helps! 😊