Next.js Discord

Discord Forum

Integrating Next-Auth with existing NestJS backend

Unanswered
Dareon posted this in #help-forum
Open in Discord
Avatar
DareonOP
Hello everyone, I have a question regarding authentication in Next.js. I currently have a custom NestJS backend that handles authentication using JWTs, with refresh tokens stored in a database and Passport.js for handling authentication. Given this setup, would there be any benefit in integrating Next-Auth into my application? Is it even possible to use Next-Auth in this scenario? Additionally, if I were to create a Next.js API endpoint that calls my NestJS backend, would this add significant latency compared to making direct calls from the frontend to the NestJS backend? Any insights would be greatly appreciated!

3 Replies

Avatar
Rafael Almeida
If you alredy have a back-end that handles authentication I don't see many reasons to use next-auth. Calling your API through a Next.js API endpoint does introduce a very very small latency but if you need to do it there's no issue, it is very common to proxy APIs to avoid CORS issues
Avatar
DareonOP
thanks for the quick response. Considering that I haven't implemented things on the client side yet, then perhaps using the hooks provided by Next-Auth could at the very least speed up my development process? it does handle refreshing of tokens doesnt it

or what would be the (few) reasons for still using Next-Auth, that you can think of?
Avatar
Rafael Almeida
The hooks are the only thing I can think of, I don't really use this library but I am pretty sure you can't integrate it with another API that already handles everything for auth