From 46c212363f04e9f992d59ce53af64fd93e6ab966 Mon Sep 17 00:00:00 2001 From: Vlad Date: Thu, 7 Jan 2016 16:44:05 +0200 Subject: [PATCH] Changed popup to redirect mode, updated dependencies --- example/socketsio-auth0-sample/package.json | 6 +- .../socketsio-auth0-sample/views/index.jade | 119 +++++++++--------- 2 files changed, 63 insertions(+), 62 deletions(-) diff --git a/example/socketsio-auth0-sample/package.json b/example/socketsio-auth0-sample/package.json index f2bf0dd..c7b9d64 100644 --- a/example/socketsio-auth0-sample/package.json +++ b/example/socketsio-auth0-sample/package.json @@ -7,9 +7,9 @@ "license": "MIT", "dependencies": { "dotenv": "^1.2.0", - "express": "^4.10.2", + "express": "^4.13.3", "jade": "^1.11.0", - "socket.io": "^1.3.6", - "socketio-jwt": "^4.3.1" + "socket.io": "^1.3.7", + "socketio-jwt": "^4.3.3" } } diff --git a/example/socketsio-auth0-sample/views/index.jade b/example/socketsio-auth0-sample/views/index.jade index 6afedcd..d397d9f 100644 --- a/example/socketsio-auth0-sample/views/index.jade +++ b/example/socketsio-auth0-sample/views/index.jade @@ -1,68 +1,69 @@ extends layout block content - script(src="https://cdn.auth0.com/js/lock-7.12.js") - script(src="/socket.io/socket.io.js") - script(src="http://code.jquery.com/jquery-1.11.1.js") - - - div#login - button.btn Login - div#chat - ul#messages - form(action="") - input(id="m" autocomplete="off") - button.btn Send + script(src="https://cdn.auth0.com/js/lock-8.1.1.js") + script(src="/socket.io/socket.io.js") + script(src="http://code.jquery.com/jquery-1.11.3.js") - script. - var userProfile; - var userToken; - var lock = new Auth0Lock('#{env.AUTH0_CLIENT_ID}', '#{env.AUTH0_DOMAIN}'); - $('#chat').hide(); - $('#login button').click(function(e){ - e.preventDefault(); - lock.show(function(err, profile, token) { - if (err) { - //Error callback - alert('There was an error'); - alert(err); - } else { - console.log('connected and authenticated'); - //Success callback - userToken = token; - //Save the JWT token - localStorage.setItem('userToken', token); + div#login + button.btn Login + div#chat + ul#messages + form(action="") + input(id="m" autocomplete="off") + button.btn Send + + script. + var userProfile; + var userToken; + var lock = new Auth0Lock('#{env.AUTH0_CLIENT_ID}', '#{env.AUTH0_DOMAIN}'); + var hash = lock.parseHash(); + $('#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(); + }); + } + } + + function openChat() { + var socket = io(); + socket.on('connect', function () { + socket.on('authenticated', function () { + //Do + $('#login').hide(); + $('#chat').show(); + $('form').submit(function (event) { + socket.emit('chat message', $('#m').val()); + $('#m').val(''); + return false; + }); + socket.on('chat message', function (msg) { + console.log("msg"); + $('#messages').append($('
  • ').text(msg)); + }); + }).emit('authenticate', {token: userToken}); // send the jwt + }) + }; - //Save the profile - userProfile = profile; - openChat(); - } - }) - }); - function openChat(){ - var socket = io(); - socket.on('connect', function () { - socket.on('authenticated', function () { - //Do - $('#login').hide(); - $('#chat').show(); - $('form').submit(function(event){ - socket.emit('chat message', $('#m').val()); - $('#m').val(''); - return false; - }); - socket.on('chat message', function(msg){ - console.log("msg"); - $('#messages').append($('
  • ').text(msg)); - }); - }) - .emit('authenticate', {token: userToken}); // send the jwt - }) - }; - - -