Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NextJS OAuth2 authentication server side without express

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?

like image 956
roeland Avatar asked Apr 29 '26 04:04

roeland


1 Answers

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

like image 143
roeland Avatar answered May 02 '26 18:05

roeland



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!