import React, { Component } from 'react';
import { Redirect } from 'react-router';
class MyAccountPage extends Component {
constructor(props) {
super(props);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleSubmit(event) {
const logout = this.props.logout;
event.preventDefault();
fetch('/logout', {
method: 'POST'
}).then(
res => res.json()
).then(function(res){
if (res.error) {
console.error(res.error); // tell user
} else {
logout();
console.log(res); // redirect back
}
}).catch(
err => console.error(err)
);
}
render() {
if (this.props && this.props.user) {
return (
Welcome, {this.props.user.username}
);
} else {
return (
)
}
}
}
export default MyAccountPage;