summaryrefslogtreecommitdiffstats
path: root/frontend/components/Signout.js
blob: 97eef4000f54979ec4c0c700d3ed5b6ae19c026d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import React, { Component } from 'react';
import { graphql, compose } from 'react-apollo';
import { CURRENT_USER_QUERY } from '../queries';

class Signout extends Component {
  signout = () => {
    console.log('Signing Out');
    localStorage.removeItem('token');
    this.props.currentUser.refetch();
  };

  render() {
    const { me, loading, error } = this.props.currentUser;
    if (!me || loading || error) return null;
    return <button onClick={this.signout}>Sign Out of {me.id}👋 🏻</button>;
  }
}

const userEnhancer = graphql(CURRENT_USER_QUERY, { name: 'currentUser' });
export default compose(userEnhancer)(Signout);