From 11e93a18b35183f3d184b4ef6003f9339f09084b Mon Sep 17 00:00:00 2001 From: Tom Russell Date: Sun, 30 Sep 2018 20:29:46 +0100 Subject: [PATCH] Sprinkle credentials: same-origin on authenticated fetches --- app/src/frontend/building-edit.js | 3 ++- app/src/frontend/my-account.js | 5 +++-- app/src/frontend/signup.js | 7 +++++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/src/frontend/building-edit.js b/app/src/frontend/building-edit.js index b4a6d304..10b47c34 100644 --- a/app/src/frontend/building-edit.js +++ b/app/src/frontend/building-edit.js @@ -74,7 +74,8 @@ class BuildingEdit extends Component { body: JSON.stringify(this.state), headers:{ 'Content-Type': 'application/json' - } + }, + credentials: 'same-origin' }).then( res => res.json() ).then(function(res){ diff --git a/app/src/frontend/my-account.js b/app/src/frontend/my-account.js index 0fa25ed1..9fc765f0 100644 --- a/app/src/frontend/my-account.js +++ b/app/src/frontend/my-account.js @@ -17,7 +17,8 @@ class MyAccountPage extends Component { this.setState({error: undefined}); fetch('/logout', { - method: 'POST' + method: 'POST', + credentials: 'same-origin' }).then( res => res.json() ).then(function(res){ @@ -32,7 +33,7 @@ class MyAccountPage extends Component { } render() { - if (this.props && this.props.user) { + if (this.props.user && !this.props.user.error) { return (
diff --git a/app/src/frontend/signup.js b/app/src/frontend/signup.js index d6f2a8d3..76cfb744 100644 --- a/app/src/frontend/signup.js +++ b/app/src/frontend/signup.js @@ -41,14 +41,17 @@ class SignUp extends Component { body: JSON.stringify(this.state), headers:{ 'Content-Type': 'application/json' - } + }, + credentials: 'same-origin' }).then( res => res.json() ).then(function(res){ if (res.error) { this.setState({error: res.error}) } else { - fetch('/users/me').then( + fetch('/users/me', { + credentials: 'same-origin' + }).then( (res) => res.json() ).then( (user) => this.props.login(user)