summaryrefslogtreecommitdiffstats
path: root/components/LoginAuth0.js
diff options
context:
space:
mode:
authorWes Bos <wesbos@gmail.com>2017-08-25 09:33:53 -0400
committerWes Bos <wesbos@gmail.com>2017-08-25 09:33:53 -0400
commit7af74ff8988961c988f03c95961b70c2918521ae (patch)
treed73cd0dd94751b76595b7febcae4162811c2040b /components/LoginAuth0.js
parent416c2cbae0e69b724876d232bf813eefd7550174 (diff)
yay
Diffstat (limited to 'components/LoginAuth0.js')
-rw-r--r--components/LoginAuth0.js58
1 files changed, 58 insertions, 0 deletions
diff --git a/components/LoginAuth0.js b/components/LoginAuth0.js
new file mode 100644
index 0000000..d5293b5
--- /dev/null
+++ b/components/LoginAuth0.js
@@ -0,0 +1,58 @@
+import { Component, PropTypes } from 'react'
+import Auth0Lock from 'auth0-lock'
+
+class LoginAuth0 extends Component {
+
+ constructor (props) {
+ super(props)
+ if(typeof window === 'undefined') return;
+ const redirectUrl = `http://localhost:3000/signup`;
+ console.log(redirectUrl);
+ this._lock = new Auth0Lock('l851ev2q8X48wf56eGLjIWFbMwwbvWPE', 'wesbos.auth0.com', {
+ auth: {
+ redirect: false,
+ }
+ });
+ }
+
+ createUser = () => {
+ 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.history.replace("/");
+ })
+ .catch(e => {
+ console.error(e);
+ this.props.history.replace("/");
+ });
+ };
+
+ componentDidMount() {
+ console.log('MOUNT');
+ this._lock.on('authenticated', (authResult) => {
+ console.log('HIIIIIIII')
+ window.localStorage.setItem('auth0IdToken', authResult.idToken)
+ console.log('Done!', authResult);
+ })
+ }
+
+ _showLogin = () => {
+ this._lock.show()
+ }
+
+ render() {
+ return (
+ <div>
+ <button onClick={this._showLogin}>Log in with Auth0 </button>
+ </div>
+ )
+ }
+}
+
+export default LoginAuth0;