03-11-2023
This commit is contained in:
@@ -254,12 +254,12 @@ class Annotation {
|
||||
|
||||
class Network {
|
||||
public getEnvelope(envelopeKey: string): Promise<any> {
|
||||
return fetch(`/api/envelope/${envelopeKey}`, { credentials: "include" })
|
||||
return fetch(`/api/envelope/${envelopeKey}`, this.withCSRFToken({ credentials: "include" }))
|
||||
.then(res => res.json());
|
||||
}
|
||||
|
||||
public getDocument(envelopeKey: string, documentId: number): Promise<ArrayBuffer> {
|
||||
return fetch(`/api/document/${envelopeKey}?index=${documentId}`, { credentials: "include" })
|
||||
return fetch(`/api/document/${envelopeKey}?index=${documentId}`, this.withCSRFToken({ credentials: "include" }))
|
||||
.then(res => res.arrayBuffer());
|
||||
}
|
||||
|
||||
@@ -272,7 +272,7 @@ class Network {
|
||||
}
|
||||
|
||||
console.debug("PostDocument/Calling url: " + url)
|
||||
return fetch(url, options)
|
||||
return fetch(url, this.withCSRFToken(options))
|
||||
.then(this.handleResponse)
|
||||
.then((res: Response) => {
|
||||
if (!res.ok) {
|
||||
@@ -291,7 +291,7 @@ class Network {
|
||||
}
|
||||
|
||||
console.debug("PostEnvelope/Calling url: " + url)
|
||||
return fetch(url, options)
|
||||
return fetch(url, this.withCSRFToken(options))
|
||||
.then(this.handleResponse)
|
||||
.then((res: Response) => {
|
||||
if (!res.ok) {
|
||||
@@ -319,7 +319,7 @@ class Network {
|
||||
}
|
||||
|
||||
console.debug("PostHistory/Calling url: " + url)
|
||||
return fetch(url, options)
|
||||
return fetch(url, this.withCSRFToken(options))
|
||||
.then(this.handleResponse)
|
||||
.then((res: Response) => {
|
||||
if (!res.ok) {
|
||||
@@ -329,6 +329,14 @@ class Network {
|
||||
});
|
||||
}
|
||||
|
||||
private withCSRFToken(options: RequestInit): RequestInit {
|
||||
const token = (document.getElementsByName("__RequestVerificationToken")[0] as any).value;
|
||||
let headers = options.headers;
|
||||
options.headers = { ...headers, 'X-XSRF-TOKEN': token };
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
private handleResponse(res: Response) {
|
||||
if (!res.ok) {
|
||||
console.log(`Request failed with status ${res.status}`)
|
||||
|
||||
Reference in New Issue
Block a user