index.jsx 689 B

1234567891011121314151617181920212223242526272829303132333435
  1. import React, { Component } from "react";
  2. import io from "io";
  3. export default class Login extends Component {
  4. constructor() {
  5. super();
  6. this.state = {};
  7. this.logout = this.logout.bind(this);
  8. }
  9. logout() {
  10. io.getSocket(socket => {
  11. socket.emit("users.logout", res => {
  12. if (res.status === "success") {
  13. document.cookie = "SID=;expires=Thu, 01 Jan 1970 00:00:01 GMT;";
  14. location.reload(); // if we could avoid this, then that would be better
  15. } else {
  16. // TODO change this
  17. alert(res.message); // eslint-disable-line no-alert
  18. }
  19. });
  20. });
  21. }
  22. render() {
  23. return (
  24. <div>
  25. <button onClick={ this.logout }>Logout</button>
  26. </div>
  27. );
  28. }
  29. }