Sharon
12/04/2025, 1:01 PMapp.domain.com (and maybe app.dev1.domain.com for the dev app) and my BE is on api.us1.domain.com / api.dev1.domain.com .
IfI understood correctly, I should configure auth.app.domain.com as my custom domain and set the CNAME record on it.
This makes sense to me for the refresh token, but I'm wondering how this will play out from the session token itself.
The cookie will be stored on app.domain.com, but since the api is on different domain it won't be able to get it. Does that force me to manage the session token in the response body?Rahul Rijhwani
12/04/2025, 2:01 PMauth.app.domain.com, but you have two options for handling the session token with your backend on a different domain:
Option 1: Use Authorization Header (Recommended)
You don't need cookies to reach your backend. Use getSessionToken() to retrieve the token and pass it in the Authorization header:
import { getSessionToken } from '@descope/react-sdk';
export const fetchData = async () => {
const sessionToken = getSessionToken();
const res = await fetch('/path/to/server/api', {
headers: {
Authorization: `Bearer ${sessionToken}`,
},
});
// ... use res
};
This approach keeps your refresh token secure in cookies on auth.app.domain.com while allowing your session token to be sent to any backend domain via headers.
Option 2: Manage in Response Body
Yes, if you need the backend to access the session token via cookies, you'd need to manage it in the response body. However, this is less secure as tokens in localStorage are vulnerable to XSS attacks.
Key Point: The cookie-based approach is primarily for securing the refresh token. For API calls to different domains, the Authorization header method is the recommended pattern.
Check docs : https://docs.descope.com/how-to-deploy-to-production/custom-domain
https://docs.descope.com/security-best-practices/session-token-storage
https://docs.descope.com/management/project-settings/refresh-token-storageSharon
12/04/2025, 2:19 PMManage in cookies or should I keep it as Manage in response body?Rahul Rijhwani
12/05/2025, 5:56 AMManage in response body
When using the getSessionToken() approach with the Authorization header, the session token needs to be accessible to your frontend JavaScript code. If you set it to "Manage in cookies," Descope would set it as an httpOnly cookie, which JavaScript cannot access.
Here's the setup:
• Session Token: "Manage in response body" - stored in localStorage, accessible via getSessionToken()
• Refresh Token: "Manage in cookies" - stored as httpOnly cookie on your custom domain auth.app.domain.com
Check doc: https://docs.descope.com/security-best-practices/session-token-storage
https://docs.descope.com/management/project-settingsSharon
12/05/2025, 12:41 PM.domain.com so it will be send to my BE on api.us.domain.com while my auth domain is on auth.app.domain.com?