How to set cookie for multiple domains in Adonisjs? #4157
Unanswered
lenikhilsingh
asked this question in
Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi guys, Let's say I own these two domains:
services.domain.network
andservices.domain.com
I have created a login API at
services.domain.network
. It sets the cookie forservices.domain.network
And subsequently, when I call other APIs at
services.domain.network,
the same cookie is used automatically by the browser(or Postman).What I need is, once the cookie is set after calling the login API, I should be able to use the APIs of
services.domain.com
as well, using the same cookie set by the login API ofservices.domain.network
.How is this possible?
I checked the Adonisjs documentation to set the domain for a cookie. Here's my config:
cookie: { domain: 'sd.domain.network,services.domain.com,localhost', path: '/', maxAge: '2h', httpOnly: true, secure: true, sameSite: 'none', },
After using this, this is the
set-cookie
header value in postman:cookie-name=s%3AeyJtZXNzYWdlIjoiY2xod2Vybm01MAwMXgzcTM2aXJiZmdxciIsInB1cnBvc2UiOiJ2ZWVkLXNlcnZpY2VzIn0._FgEtW1HXcuLOd-EjJsVVNjMhzIxp3pa7DuwUDf_a_k; Max-Age=1296000; Domain=sd.domain.network,services.domain.com,localhost; Path=/; SameSite=None
Notice the
Domain
attribute, which contains the domains I require. But it doesn't work, since cookie is not getting saved in postman or the browser.No cookies received from the server
Beta Was this translation helpful? Give feedback.
All reactions