From f115bbabb19024b919a79c910fce79a5ed9cfa6a Mon Sep 17 00:00:00 2001 From: Vlad Date: Mon, 11 Jul 2016 23:07:28 +0300 Subject: [PATCH 1/2] lock v10 update --- .../public/stylesheets/style.css | 6 +-- .../socketsio-auth0-sample/views/index.pug | 48 +++++++++++-------- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/example/socketsio-auth0-sample/public/stylesheets/style.css b/example/socketsio-auth0-sample/public/stylesheets/style.css index f032aee..2e749fe 100644 --- a/example/socketsio-auth0-sample/public/stylesheets/style.css +++ b/example/socketsio-auth0-sample/public/stylesheets/style.css @@ -1,8 +1,8 @@ * { margin: 0; padding: 0; box-sizing: border-box; } body { font: 13px Helvetica, Arial; } -form { background: #000; padding: 3px; position: fixed; bottom: 0; width: 100%; } -form input { border: 0; padding: 10px; width: 90%; margin-right: .5%; } -form button { width: 9%; background: rgb(130, 224, 255); border: none; padding: 10px; } +#chatForm { background: #000; padding: 3px; position: fixed; bottom: 0; width: 100%; } +#chatForm input { border: 0; padding: 10px; width: 90%; margin-right: .5%; } +#chatForm button { width: 9%; background: rgb(130, 224, 255); border: none; padding: 10px; } #messages { list-style-type: none; margin: 0; padding: 0; } #messages li { padding: 5px 10px; } #messages li:nth-child(odd) { background: #eee; } diff --git a/example/socketsio-auth0-sample/views/index.pug b/example/socketsio-auth0-sample/views/index.pug index 774d2f0..f8f5af6 100644 --- a/example/socketsio-auth0-sample/views/index.pug +++ b/example/socketsio-auth0-sample/views/index.pug @@ -1,7 +1,7 @@ extends layout block content - script(src="https://cdn.auth0.com/js/lock-9.2.min.js") + script(src="https://cdn.auth0.com/js/lock/10.0.0-rc.2/lock.min.js") script(src="/socket.io/socket.io.js") script(src="http://code.jquery.com/jquery-1.12.4.js") @@ -10,7 +10,7 @@ block content button.btn Login div#chat ul#messages - form(action="") + form(id="chatForm" action="") input(id="m" autocomplete="off") button.btn Send @@ -18,30 +18,36 @@ block content var userProfile; var userToken; var lock = new Auth0Lock('#{env.AUTH0_CLIENT_ID}', '#{env.AUTH0_DOMAIN}'); - var hash = lock.parseHash(); + var id_token = localStorage.getItem('id_token'); $('#chat').hide(); $('#login button').click(function (e) { e.preventDefault(); lock.show(); }); - if (hash) { - if (hash.error) { - console.log("There was an error logging in", hash.error); - } - else { - lock.getProfile(hash.id_token, function (err, profile) { - if (err) { - console.log('Cannot get user', err); - return; - } - console.log('connected and authenticated'); - userProfile = profile; - localStorage.setItem('userToken', hash.id_token); - userToken = hash.id_token; - openChat(); - }); - } + lock.on('authenticated', function(authResult) { + lock.getProfile(authResult.idToken, function(error, profile) { + if (error) { + // Handle error + return; + } + console.log('connected and authenticated'); + localStorage.setItem('id_token', authResult.idToken); + localStorage.setItem('profile', JSON.stringify(profile)); + userProfile = profile; + id_token = authResult.idToken; + openChat(); + }); + }); + + if (id_token) { + lock.getProfile(id_token, function (err, profile) { + if (err) { + return alert('There was an error getting the profile: ' + err.message); + } + userProfile = profile; + openChat(); + }); } function openChat() { @@ -49,7 +55,7 @@ block content socket .on('connect', function (msg) { console.log("connected"); - socket.emit('authenticate', {token: userToken}); // send the jwt + socket.emit('authenticate', {token: id_token}); // send the jwt }) .on('authenticated', function () { //Do From aed1aeb7653a3d975c4af85a3ddf7b759aaca9e4 Mon Sep 17 00:00:00 2001 From: Vlad Date: Thu, 21 Jul 2016 18:14:59 +0300 Subject: [PATCH 2/2] bumped lock version --- example/socketsio-auth0-sample/views/index.pug | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/socketsio-auth0-sample/views/index.pug b/example/socketsio-auth0-sample/views/index.pug index f8f5af6..3175adc 100644 --- a/example/socketsio-auth0-sample/views/index.pug +++ b/example/socketsio-auth0-sample/views/index.pug @@ -1,7 +1,7 @@ extends layout block content - script(src="https://cdn.auth0.com/js/lock/10.0.0-rc.2/lock.min.js") + script(src="https://cdn.auth0.com/js/lock/10.0/lock.min.js") script(src="/socket.io/socket.io.js") script(src="http://code.jquery.com/jquery-1.12.4.js")