Sprinkle credentials: same-origin on authenticated fetches

This commit is contained in:
Tom Russell 2018-09-30 20:29:46 +01:00
parent aae5c1ca32
commit 11e93a18b3
3 changed files with 10 additions and 5 deletions

View File

@ -74,7 +74,8 @@ class BuildingEdit extends Component {
body: JSON.stringify(this.state), body: JSON.stringify(this.state),
headers:{ headers:{
'Content-Type': 'application/json' 'Content-Type': 'application/json'
} },
credentials: 'same-origin'
}).then( }).then(
res => res.json() res => res.json()
).then(function(res){ ).then(function(res){

View File

@ -17,7 +17,8 @@ class MyAccountPage extends Component {
this.setState({error: undefined}); this.setState({error: undefined});
fetch('/logout', { fetch('/logout', {
method: 'POST' method: 'POST',
credentials: 'same-origin'
}).then( }).then(
res => res.json() res => res.json()
).then(function(res){ ).then(function(res){
@ -32,7 +33,7 @@ class MyAccountPage extends Component {
} }
render() { render() {
if (this.props && this.props.user) { if (this.props.user && !this.props.user.error) {
return ( return (
<article> <article>
<section className="main-col"> <section className="main-col">

View File

@ -41,14 +41,17 @@ class SignUp extends Component {
body: JSON.stringify(this.state), body: JSON.stringify(this.state),
headers:{ headers:{
'Content-Type': 'application/json' 'Content-Type': 'application/json'
} },
credentials: 'same-origin'
}).then( }).then(
res => res.json() res => res.json()
).then(function(res){ ).then(function(res){
if (res.error) { if (res.error) {
this.setState({error: res.error}) this.setState({error: res.error})
} else { } else {
fetch('/users/me').then( fetch('/users/me', {
credentials: 'same-origin'
}).then(
(res) => res.json() (res) => res.json()
).then( ).then(
(user) => this.props.login(user) (user) => this.props.login(user)