I would like to add OAuth2 authentication (I will start with Google) to my NextJS app without using an extra service like Auth0.
This would be possible with PassportJS, but then I need to add Express as a custom server and I will loose some advantages of NextJS.
Next has middleware support but for only for connect: https://nextjs.org/docs/api-routes/api-middlewares
I don't want a client only solution. I prefer server side with http-only cookies.
What is the best solution?
Update: You can now use this: https://next-auth.js.org/
Old answer:
I seems that I can use PassportJS with this: https://www.npmjs.com/package/next-connect
Next-connect allows middleware similar to Express.
Here is an example of using PassportJS: https://github.com/hoangvvo/nextjs-mongodb-app
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With