lock v10 update
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user