next.jsjwthttp-proxyhttp-proxy-middleware

Using JWT cookie between nextjs and back-end api


I have a nodejs express back-end api which is implemented with authentication approach of JWT + cookie . Now I want to connect it with a nextjs front-end which is on another domain . I know this is viable with proxy, but since nextjs app needs the api content on the build time, how is it possible to receive the api data through proxy while the fron-end app ( which contains proxy to back-end domain ) is not still installed completely ?

I case you know an example I would appreciate to show me .


Solution

  • I believe that this package is what you need : next-http-proxy-middleware

    https://www.npmjs.com/package/next-http-proxy-middleware