summaryrefslogtreecommitdiffstats
path: root/components/LoginAuth0.js
diff options
context:
space:
mode:
authorWes Bos <wesbos@gmail.com>2017-09-21 15:39:12 -0400
committerWes Bos <wesbos@gmail.com>2017-09-21 15:39:12 -0400
commit3b45dd7b593825721ec9ee9f6a49c732601b1ae0 (patch)
treea2e8e73d6b6b6bc32eda2bb79af817397e4304f5 /components/LoginAuth0.js
parent1450e579c67e3d969cb099dfe6c1cefd1e313fb5 (diff)
Cha Ching
Diffstat (limited to 'components/LoginAuth0.js')
-rw-r--r--components/LoginAuth0.js58
1 files changed, 29 insertions, 29 deletions
diff --git a/components/LoginAuth0.js b/components/LoginAuth0.js
index 262d8bd..8691e82 100644
--- a/components/LoginAuth0.js
+++ b/components/LoginAuth0.js
@@ -1,70 +1,70 @@
-import { Component, PropTypes } from 'react'
-import Auth0Lock from 'auth0-lock'
-import { graphql, compose } from 'react-apollo'
+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 {
-
- constructor (props) {
- super(props)
- if(typeof window === 'undefined') return;
- const redirectUrl = `http://localhost:3000/signup`;
- console.log(redirectUrl);
+ constructor(props) {
+ super(props);
+ if (typeof window === 'undefined') return;
+ const redirectUrl = `http://localhost:6969/signup`;
this._lock = new Auth0Lock('l851ev2q8X48wf56eGLjIWFbMwwbvWPE', 'wesbos.auth0.com', {
auth: {
redirect: false,
- }
+ },
});
}
+ componentDidMount() {
+ console.log('MOUNT');
+ this._lock.on('authenticated', authResult => {
+ window.localStorage.setItem('auth0IdToken', authResult.idToken);
+ this.props.currentUserQuery.refetch();
+ });
+ // refech on page load because of the server render
+ this.props.currentUserQuery.refetch();
+ }
+
logout = () => {
window.localStorage.removeItem('auth0IdToken');
this.props.currentUserQuery.refetch();
- }
+ };
- createUser = () => {
+ createUser = async () => {
const variables = {
idToken: window.localStorage.getItem('auth0IdToken'),
emailAddress: 'wesbos@gmail.com',
- name: 'Hardcoded Wes'
+ name: 'Hardcoded Wes',
};
// TODO - make a createUser function
this.props
.createUser({ variables })
.then(response => {
// this.props.currentUserQuery.refetch();
- this.props.history.replace("/");
+ this.props.history.replace('/');
})
.catch(e => {
console.error(e);
- this.props.history.replace("/");
+ this.props.history.replace('/');
});
};
- componentDidMount() {
- console.log('MOUNT');
- this._lock.on('authenticated', (authResult) => {
- window.localStorage.setItem('auth0IdToken', authResult.idToken)
- this.props.currentUserQuery.refetch();
- })
- }
-
_showLogin = () => {
- this._lock.show()
- }
+ this._lock.show();
+ };
render() {
const { user } = this.props.currentUserQuery;
- if ( user ) {
- return <button onClick={this.logout}>Log out 👋</button>
+ if (user) {
+ return <button onClick={this.logout}>Log out 👋</button>;
}
return (
<div>
<button onClick={this._showLogin}>Log in with Auth0 </button>
</div>
- )
+ );
}
}
const userEnhancer = graphql(CURRENT_USER_QUERY, { name: 'currentUserQuery' });
-export default compose(userEnhancer)(LoginAuth0)
+export default compose(userEnhancer)(LoginAuth0);