Hi everyone,
I’m currently facing an issue with cookie-based authentication across subdomains. Here’s the setup of my application:
- Backend (Frappe app) is hosted on:
https://backend.domain.com
- Frontend (Next.js app) is hosted on:
https://frontend.domain.com
Goal
I want users to be able to log in from the Next.js frontend, and then authenticate with Frappe using the session cookie (sid
), so that authenticated requests to Frappe API work seamlessly.
The Problem
When I perform login from the frontend (frontend.orecon.co.id
) to the Frappe backend (backend.domain.co.id
), the API returns 200 OK
and includes a Set-Cookie
header for the sid
.
However:
- The
sid
cookie does not get stored in the browser (visible in DevTools > Application > Cookies). - As a result, subsequent requests do not include the session cookie, even though login succeeded.
- I suspect this is due to incorrect
SameSite
orDomain
attributes in theSet-Cookie
header.
Things I’ve Tried
On the Frappe side:
- Enabled CORS via
site_config.json
:
"allow_cors": "https://frontend.domain.com"
On the Next.js side:
await fetch('https://backend.domain.com/api/method/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
credentials: 'include', // included this to send/receive cookies
body: JSON.stringify({ usr: 'user', pwd: 'password' }),
});
Both domains use HTTPS
Observations
- The login API returns 200 OK, with
Set-Cookie
present. - But the browser (Chrome) does not store the cookie.
- There are no CORS errors in console, but still cookie isn’t persisted.
Question
What am I missing to make Frappe’s cookie-based authentication work across subdomains?
Any Frappe config or headers I need to adjust further?
Thanks a lot in advance!