From b0955ddaa6dc95574fa31a8de327cb81ef03aa0d Mon Sep 17 00:00:00 2001 From: Alexar Date: Sun, 16 Feb 2020 08:36:36 +1100 Subject: [PATCH 1/2] 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": [ From 135379b99d777d9065067342516cf7cb8f7b13c2 Mon Sep 17 00:00:00 2001 From: Alexar Date: Sun, 16 Feb 2020 08:46:52 +1100 Subject: [PATCH 2/2] Minor UX improvement --- favorite/js/favorite.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/favorite/js/favorite.js b/favorite/js/favorite.js index 50b6f6b..dc2e5de 100644 --- a/favorite/js/favorite.js +++ b/favorite/js/favorite.js @@ -58,7 +58,8 @@ class Favorite extends Component { }); } - toggleFavorite() { + toggleFavorite(e) { + e.preventDefault() var favorited = !this.state.favorited; this.saveFavorite(favorited); }