forked from auth0/angular-lock
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathangular-lock.js
More file actions
66 lines (55 loc) · 1.56 KB
/
Copy pathangular-lock.js
File metadata and controls
66 lines (55 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
;(function() {
'use strict';
angular
.module('auth0.lock', [])
.provider('lock', lock);
function lock() {
if (typeof Auth0Lock !== 'function') {
throw new Error('Auth0Lock must be loaded.');
}
this.init = function(config) {
if (!config) {
throw new Error('clientID and domain must be provided to lock');
}
this.clientID = config.clientID;
this.domain = config.domain;
this.options = config.options || {};
}
this.$inject = ['$rootScope'];
this.$get = function($rootScope) {
var Lock = new Auth0Lock(this.clientID, this.domain, this.options);
var lock = {};
function safeApply(fn) {
var phase = $rootScope.$root.$$phase;
if(phase === '$apply' || phase === '$digest') {
if(fn && (typeof(fn) === 'function')) {
fn();
}
} else {
$rootScope.$apply(fn);
}
}
lock.show = function() {
Lock.show();
}
lock.on = function(event, cb) {
var lockEvents = ['show', 'hide', 'error', 'authenticated', 'authorization_error'];
if(lockEvents.indexOf(event) !== -1) {
Lock.on(event, function(data) {
safeApply(function() {
cb(data);
});
});
}
}
lock.getProfile = function(token, cb) {
Lock.getProfile(token, function(error, data) {
safeApply(function() {
cb(error, data);
});
});
}
return lock;
}
}
})();