From 1450e579c67e3d969cb099dfe6c1cefd1e313fb5 Mon Sep 17 00:00:00 2001 From: Wes Bos Date: Fri, 15 Sep 2017 14:26:13 -0400 Subject: yep --- components/LoginAuth0.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'components/LoginAuth0.js') diff --git a/components/LoginAuth0.js b/components/LoginAuth0.js index d5293b5..262d8bd 100644 --- a/components/LoginAuth0.js +++ b/components/LoginAuth0.js @@ -1,5 +1,7 @@ import { Component, PropTypes } from 'react' import Auth0Lock from 'auth0-lock' +import { graphql, compose } from 'react-apollo' +import { CURRENT_USER_QUERY } from '../queries/index'; class LoginAuth0 extends Component { @@ -15,9 +17,14 @@ class LoginAuth0 extends Component { }); } + logout = () => { + window.localStorage.removeItem('auth0IdToken'); + this.props.currentUserQuery.refetch(); + } + createUser = () => { const variables = { - idToken: window.localStorage.getItem("auth0IdToken"), + idToken: window.localStorage.getItem('auth0IdToken'), emailAddress: 'wesbos@gmail.com', name: 'Hardcoded Wes' }; @@ -25,6 +32,7 @@ class LoginAuth0 extends Component { this.props .createUser({ variables }) .then(response => { + // this.props.currentUserQuery.refetch(); this.props.history.replace("/"); }) .catch(e => { @@ -36,9 +44,8 @@ class LoginAuth0 extends Component { componentDidMount() { console.log('MOUNT'); this._lock.on('authenticated', (authResult) => { - console.log('HIIIIIIII') window.localStorage.setItem('auth0IdToken', authResult.idToken) - console.log('Done!', authResult); + this.props.currentUserQuery.refetch(); }) } @@ -47,6 +54,10 @@ class LoginAuth0 extends Component { } render() { + const { user } = this.props.currentUserQuery; + if ( user ) { + return + } return (
@@ -55,4 +66,5 @@ class LoginAuth0 extends Component { } } -export default LoginAuth0; +const userEnhancer = graphql(CURRENT_USER_QUERY, { name: 'currentUserQuery' }); +export default compose(userEnhancer)(LoginAuth0) -- cgit v1.3