Accessing Set-Cookie value from response.headers in axios
[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]; ```.
[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
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.