-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathService.js
More file actions
41 lines (37 loc) · 1.02 KB
/
Service.js
File metadata and controls
41 lines (37 loc) · 1.02 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
import {
createAuthenticator,
Authenticator,
} from '@cybavo/react-native-auth-service';
import AsyncStorage from '@react-native-community/async-storage';
import { SERVICE_ENDPOINT, SERVICE_API_CODE } from './BuildConfig.json';
export const Service = {
async getConfig() {
const [[, endpoint], [, apiCode]] = await AsyncStorage.multiGet([
'@service_endpoint',
'@service_api_code',
]);
return {
endpoint: endpoint || SERVICE_ENDPOINT,
apiCode: apiCode || SERVICE_API_CODE,
};
},
async setConfig({ endpoint, apiCode }) {
await AsyncStorage.multiSet([
['@service_endpoint', endpoint],
['@service_api_code', apiCode],
]);
console.log('cfg:', await this.getConfig());
},
get(): Promise<Authenticator> {
if (!this.promise) {
this.promise = new Promise(resolve =>
resolve(
this.getConfig().then(({ endpoint, apiCode }) =>
createAuthenticator(endpoint, apiCode)
)
)
);
}
return this.promise;
},
};