Immutable solution version
Accessing Set-Cookie value from response.headers in axios
Complete solution
Shows how to fix accessing Set-Cookie value from response.headers in axios. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
TL;DR
[Vasily (top answer)] This approach works, but should be handled on a server side if it's HttpOnly cookie: ` const res = await axios....; const cookieName = '...'; const cookie = (res.headers['set-cookie'] as string[]).find(cookie => cookie.includes(cookieName)) ?.match(new RegExp(^${cookieName}=(.+?);)) ?.[1]; Context: Stack Overflow #70972629 (top answer, 3 votes, 3 answers): I am using VueJS and Axios to send a request like this: axiosAPI.get('/login/flows', {params: {id: 'string'}}).then(res => { console.log('cookie', res.headers) } In return server sends me this response: `` Access
Steps
- [Vasily (top answer)] This approach works, but should be handled on a server side if it's HttpOnly cookie:
``` axiosAPI.get('/login/flows', {params: {id: 'string'}}) .then(res => { console.log('cookie', res.headers) } ```
2. In return server sends me this response: ``` Access-Control-Allow-Credentials - true Access-Control-Allow-Origin: * Access-Control-Expose-Headers: Content-Type Cache-Control: private, no-cache, no-store, must-revalidate Content-Length: 646 Content-Type: application/json; charset=utf-8 Date: Thu,xxxx 13:56:21 GMT Set-Cookie: csrf_token [your value] Path=/.ory/kratos/pub
## When to use
Use this skill when you run into "Accessing Set-Cookie value from response.headers in axios".
## When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
## Versions
No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.
## Why this happens
The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.
Evidence
Source: Stack Overflow #70972629 (top answer, 3 votes, 3 answers): I am using VueJS and Axios to send a request like this: `` axiosAPI.get('/login/flows', {params: {id: 'string'}}) .then(res => { console.log('cookie', res.headers) } In return server sends me this response: `` Access-Control-Allow-Credentials - true Access-Control-Allow-Origin: * Access-Control-Expose-Headers: Content-Type Cache-Control: private, no-cache, no-store, must-revalidate Content-Length: 646 Content-Type: application/json; charset=utf-8 Date: Thu,xxxx 13:56:21 GMT Set-Cookie: csrf_token [your value] Path=/.ory/kratos/pub
Verified resolution: [Vasily (top answer)] This approach works, but should be handled on a server side if it's HttpOnly cookie: `` const res = await axios....; const cookieName = '...'; const cookie = (res.headers['set-cookie'] as string[]) .find(cookie => cookie.includes(cookieName)) ?.match(new RegExp(^${cookieName}=(.+?);)) ?.[1];
Source URL: https://stackoverflow.com/questions/70972629
By @issueatlas · Version 3 · Exact version
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_AWhEWZPVoq-0pRzNFxIpcg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Accessing Set-Cookie value from response.headers in axios <span>— Vectle</span></a>