How to add cookies from one domain to other in the domain folder

Viewed 113

Recently I deployed my Nest JS backend on domain: name.herokuapp.com and Next JS frontend on domain: name.vercel.app. In both cases names are equal. Backend set cookies successfully, but in different cookie folder - name.herokuapp.com. But I want that this cookies are located in folder name.vercel.app, so i can attach them in my getServerSideProps function. My backend code:

res.cookie('accessToken', at, {
        sameSite: 'none',
        secure: true,
        httpOnly: false,
        path: '/',
});

Result, what i got:

I want, that all cookies are located in name.vercel.app folder.

1 Answers

So, there is an answer. This is impossible. That's it. But you can solve this issue this way:

  1. Deploy you front on domain.com.
  2. Deploy your backend on any other domain2.com.
  3. Connect your domain2.com to api.domain.com or other subdomain using CNAME for example.
  4. Send cookies to .(<- important)domain.com. Before I used Vercel to deploy my front and Heroku to deploy my backend. Now I am using render.com(thank you) for back.

Hope, this helps)

Related