From b0955ddaa6dc95574fa31a8de327cb81ef03aa0d Mon Sep 17 00:00:00 2001 From: Alexar Date: Sun, 16 Feb 2020 08:36:36 +1100 Subject: [PATCH] Fixes #2: X-CSRF-Token header missing --- favorite/js/favorite.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/favorite/js/favorite.js b/favorite/js/favorite.js index 0eab247..50b6f6b 100644 --- a/favorite/js/favorite.js +++ b/favorite/js/favorite.js @@ -15,9 +15,19 @@ class Favorite extends Component { user_uuid: '', user_uid: '0', node_type: '', - node_uuid: '' + node_uuid: '', + token: '' } - this.getData(); + this.getToken(); + } + getToken() { + fetch('/session/token', {}).then((response) => { + if (response.ok) { + response.text().then((data) => { + this.state.token = data + }) + } + }); } getData() { @@ -64,7 +74,8 @@ class Favorite extends Component { credentials: 'include', headers: { 'Accept': 'application/vnd.api+json', - 'Content-Type': 'application/vnd.api+json' + 'Content-Type': 'application/vnd.api+json', + 'X-CSRF-Token': this.state.token }, body: JSON.stringify({ "data": [