1
0
mirror of https://github.com/sasjs/adapter.git synced 2026-01-08 04:50:06 +00:00

fix(server): csrf cookie is created explicitly

This commit is contained in:
Saad Jutt
2022-08-04 05:04:43 +05:00
parent 504777603c
commit e37bb182c3
2 changed files with 19 additions and 3 deletions

View File

@@ -500,11 +500,19 @@ export class RequestClient implements HttpClient {
}
if (e instanceof InvalidCsrfError) {
// Fetching root will inject CSRF token in cookie
// Fetching root and creating CSRF cookie
await this.httpClient
.get('/', {
withCredentials: true
})
.then((response) => {
const cookie =
/<script>document.cookie = '(XSRF-TOKEN=.*; Max-Age=86400; SameSite=Strict; Path=\/;)'<\/script>/.exec(
response.data
)?.[1]
if (cookie) document.cookie = cookie
})
.catch((err) => {
throw prefixMessage(err, 'Error while re-fetching CSRF token.')
})