fathom/assets/js/components/LogoutButton.js

34 lines
608 B
JavaScript
Raw Normal View History

2016-11-23 18:40:35 +00:00
'use strict';
import { h, render, Component } from 'preact';
class LogoutButton extends Component {
constructor(props) {
super(props)
this.handleSubmit = this.handleSubmit.bind(this);
}
handleSubmit(e) {
e.preventDefault();
fetch('/api/session', {
method: "DELETE",
credentials: 'include',
}).then((r) => {
if( r.status == 200 ) {
this.props.onSuccess();
console.log("No longer authenticated!");
}
});
}
render() {
return (
<a href="#" onClick={this.handleSubmit}>Sign out</a>
)
}
}
export default LogoutButton