nextjs route middleware for authentication

前端 未结 2 720
庸人自扰
庸人自扰 2021-01-31 22:26

I\'m trying to figure out an appropriate way of doing authentication, which I know is a touchy subject on the GitHub issue page.

My authentication is simple. I store a

相关标签:
2条回答
  • 2021-01-31 22:54

    There is no middleware for no API routes in NextJS, but there are HOCs, which you can use to connect to db - select the user, etc: https://hoangvvo.com/blog/nextjs-middleware

    0 讨论(0)
  • 2021-01-31 22:55

    Tim from the next chat helped me solve this. Solution can be found here but I will quote him so you all can see:

    • You can do the check in _app.js getInitialProps and redirect like this
    • Example of how to use it
    • _app.js documentation

    I've also created an example skeleton template you can take a look at.

    0 讨论(0)
提交回复
热议问题