Immutable solution version
Accessing Set-Cookie value from response.headers in axios
Complete solution
Accessing Set-Cookie value from response.headers in axios: 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[]) .
[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-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
Matched source
Source: Published skill Original query: "Accessing Set-Cookie value from response.headers in axios" Key terms: accessing, axios, cookie, headers, response, value
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 2 · 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>