forked from auth0/react-native-lock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth0-lock.js
63 lines (55 loc) · 1.66 KB
/
auth0-lock.js
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
var { NativeModules, Platform } = require('react-native');
var LockModule = NativeModules.Auth0LockModule;
const VERSION = require('./version');
const Auth0 = require('react-native-auth0');
class Auth0Lock {
constructor(options) {
let { clientId, domain, style } = options;
if (options != null && clientId != null && domain != null) {
this.lockOptions = {
clientId: clientId,
domain: domain,
style: style,
configurationDomain: options.configurationDomain,
libraryVersion: VERSION,
useBrowser: options.useBrowser
};
this.nativeIntegrations = options.integrations;
this.auth0 = new Auth0(domain);
} else {
throw "Must supply clientId & domain";
}
}
hide(callback) {
if (Platform.OS === "android") {
setTimeout(() => callback(), 0);
return;
}
LockModule.hide(callback);
}
show(options, callback) {
LockModule.init(this.lockOptions);
if (Platform.OS === "ios" && this.nativeIntegrations) {
LockModule.nativeIntegrations(this.nativeIntegrations);
}
LockModule.show(options, callback);
}
authenticate(connectionName, options, callback) {
if (Platform.OS === "android") {
callback("Not available in Android", null, null);
return;
}
LockModule.init(this.lockOptions);
if (this.nativeIntegrations) {
LockModule.nativeIntegrations(this.nativeIntegrations);
}
LockModule.authenticate(connectionName, options, callback);
}
authenticationAPI() {
return this.auth0.authentication(this.lockOptions.clientId);
}
usersAPI(token) {
return this.auth0.users(token);
}
}
module.exports = Auth0Lock;