Can I use express passport.js session google authentication with a next.js

333 Views Asked by At

I am tring to pick out a tech stack, so I wondered if I can use express passport.js session google authentication with a next.js?

1

There are 1 best solutions below

0
On BEST ANSWER

Next has his own build in server, that you can replace by your custom like express:

So answer is: Yes you can, but it has tradeoffs.

  • some deployment options are not possible (eg next on vercel)
  • serverless functions can't be used natively
  • performance optimizations build in next and automatic static optimization are not possible

To get right decision you probably should read about next deployment. There are different support for custom servers depending from deployment option, if do you have your own vps/droplet then express always can be used with next.

There are great introduction to custom server in official docs and discussion about pros and cons of express with next.

Rest of mentioned stack: passport.js session google authentication are obviously possible to implement in express but you can also use them without express.

If you decide to not resign from build in server you can use it without express. Best place to start will be example mentioned by @iAi Dev in comment. It can be more tricky because you will have to skip all tutorials where express plugins are used and learn more about nuxt server but it can be good investment if you want to be focused on performance of flexibility of deployment or scaling.