-
Notifications
You must be signed in to change notification settings - Fork 92
/
Keychain.js
38 lines (35 loc) · 969 Bytes
/
Keychain.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
import React from "react";
import * as Keychain from "react-native-keychain";
//@flow
export const setLoginCredentials = async (field1, field2) => {
try {
const response = await Keychain.setGenericPassword(field1, field2);
console.log("keychain data securely set ", response);
return { status: true, response };
} catch (e) {
console.log("keychain access failed ", e);
return { status: false, error: e };
}
};
export const getLoginCredentials = async () => {
try {
const credentials = await Keychain.getGenericPassword();
console.log("keychain get data ", credentials);
if (credentials) {
return credentials;
}
return false;
} catch (e) {
console.log("Cannot retrieve keychain data", e);
return false;
}
};
export const resetLoginCredentials = async () => {
try {
const reset = await Keychain.resetGenericPassword();
return reset;
} catch (e) {
console.log("cannot access or reset keychain data ", e);
return false;
}
};