summaryrefslogtreecommitdiffstats
path: root/frontend/components/LoginAuth0.js
diff options
context:
space:
mode:
authorWes Bos <wesbos@gmail.com>2018-02-15 16:59:58 -0500
committerWes Bos <wesbos@gmail.com>2018-02-15 16:59:58 -0500
commit8f2c595eca30e2d7138c8e8d6685774a8f44e55d (patch)
tree3408b9c8eb3b0ea43cb72e13e0bd6393ab5bac61 /frontend/components/LoginAuth0.js
parenta09b01abf7c03e6b7e43f2175e5a34501808821b (diff)
omg
Diffstat (limited to 'frontend/components/LoginAuth0.js')
-rw-r--r--frontend/components/LoginAuth0.js76
1 files changed, 0 insertions, 76 deletions
diff --git a/frontend/components/LoginAuth0.js b/frontend/components/LoginAuth0.js
deleted file mode 100644
index b55ae4a..0000000
--- a/frontend/components/LoginAuth0.js
+++ /dev/null
@@ -1,76 +0,0 @@
-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`;
- this._lock = new Auth0Lock('r6D64Waoq7roAnv8GT04dnn1tpq9PAqu', 'wesbos.auth0.com', {
- auth: {
- redirect: false,
- },
- });
- }
-
- componentDidMount() {
- this._lock.on('authenticated', authResult => {
- console.log(authResult);
- window.localStorage.setItem('auth0IdToken', authResult.idToken);
- console.log('Im baaaack!');
- this.props.currentUserQuery.refetch();
- });
-
- this._lock.on('authorization_error', err => {
- console.error(err);
- });
-
- // refech on page load because of the server render
- this.props.currentUserQuery.refetch();
- }
-
- logout = () => {
- window.localStorage.removeItem('auth0IdToken');
- this.props.currentUserQuery.refetch();
- };
-
- createUser = async () => {
- const variables = {
- idToken: window.localStorage.getItem('auth0IdToken'),
- emailAddress: 'wesbos@gmail.com',
- name: 'Hardcoded Wes',
- };
- // TODO - make a createUser function
- this.props
- .createUser({ variables })
- .then(response => {
- // this.props.currentUserQuery.refetch();
- this.props.history.replace('/');
- })
- .catch(e => {
- console.error(e);
- this.props.history.replace('/');
- });
- };
-
- _showLogin = () => {
- this._lock.show();
- };
-
- render() {
- const { user } = this.props.currentUserQuery;
- 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);