Skip to content

Commit 97ddc65

Browse files
committed
Improved example and fixed biometric prompt
* Fixed biometric prompt crash when header/title was not provided. Now, the default is: "Unlock with your fingerprint"
1 parent 7841978 commit 97ddc65

File tree

10 files changed

+292
-45
lines changed

10 files changed

+292
-45
lines changed
File renamed without changes.

RNSensitiveInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { NativeModules } from "react-native";
1+
import { NativeModules } from 'react-native';
22

33
const { RNSensitiveInfo } = NativeModules;
44

android/src/main/java/br/com/classapp/RNSensitiveInfo/RNSensitiveInfoModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ public void run() {
337337
.setDeviceCredentialAllowed(false)
338338
.setNegativeButtonText(strings.containsKey("cancel") ? strings.get("cancel").toString() : "Cancel")
339339
.setDescription(strings.containsKey("description") ? strings.get("description").toString() : null)
340-
.setTitle(strings.containsKey("header") ? strings.get("header").toString() : null)
340+
.setTitle(strings.containsKey("header") ? strings.get("header").toString() : "Unlock with your fingerprint")
341341
.build();
342342
biometricPrompt.authenticate(promptInfo, cryptoObject);
343343
} catch (Exception e) {

example/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,5 @@ buck-out/
6262
# CocoaPods
6363
/ios/Pods/
6464

65-
.yalc
65+
.yalc
66+
.DS_Store

example/src/pages/Home/index.tsx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,41 @@ const Home: React.FC = () => {
1212

1313
const handleSetItemUsingTouchIDOnPress = useCallback(async () => {
1414
try {
15-
// const deviceHasSensor = await SInfo.isSensorAvailable();
15+
const deviceHasSensor = await SInfo.isSensorAvailable();
1616

17-
// if (!deviceHasSensor) {
18-
// return Alert.alert('No sensor found');
19-
// }
17+
if (!deviceHasSensor) {
18+
return Alert.alert(
19+
'No sensor found or fingerprint/faceID is available',
20+
);
21+
}
2022

2123
await SInfo.setItem('touchIdItem', new Date().toISOString(), {
2224
kSecAccessControl: 'kSecAccessControlBiometryAny',
2325
touchID: true,
26+
showModal: true,
2427
});
2528

2629
Alert.alert('data successfully stored');
2730
} catch (ex) {
28-
console.log(ex.message);
31+
Alert.alert('Error', ex.message);
2932
}
3033
}, []);
3134

3235
const getTouchIDItem = useCallback(async () => {
3336
const deviceHasSensor = await SInfo.isSensorAvailable();
3437

35-
// if (!deviceHasSensor) {
36-
// return Alert.alert('No sensor found');
37-
// }
38+
if (!deviceHasSensor) {
39+
return Alert.alert('No sensor found or fingerprint/faceID is available');
40+
}
3841

3942
try {
4043
const data = await SInfo.getItem('touchIdItem', {
4144
touchID: true,
45+
showModal: true,
46+
strings: {
47+
description: 'Custom Title ',
48+
header: 'Custom Description',
49+
},
4250
kSecUseOperationPrompt:
4351
'We need your permission to retrieve encrypted data',
4452
});

example/yalc.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"version": "v1",
33
"packages": {
44
"react-native-sensitive-info": {
5-
"signature": "2394e5f13888f518cb522843ee7d8bba",
5+
"signature": "f4c959239af07bc61ded9fd61a71e37e",
66
"file": true
77
}
88
}

index.d.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
type RNSensitiveInfoBiometryType = "Touch ID" | "Face ID";
1+
type RNSensitiveInfoBiometryType = 'Touch ID' | 'Face ID';
22

33
type RNSensitiveInfoAccessControlOptions =
4-
| "kSecAccessControlApplicationPassword"
5-
| "kSecAccessControlPrivateKeyUsage"
6-
| "kSecAccessControlDevicePasscode"
7-
| "kSecAccessControlTouchIDAny"
8-
| "kSecAccessControlTouchIDCurrentSet"
9-
| "kSecAccessControlUserPresence"
10-
| "kSecAccessControlBiometryAny"
11-
| "kSecAccessControlBiometryCurrentSet";
4+
| 'kSecAccessControlApplicationPassword'
5+
| 'kSecAccessControlPrivateKeyUsage'
6+
| 'kSecAccessControlDevicePasscode'
7+
| 'kSecAccessControlTouchIDAny'
8+
| 'kSecAccessControlTouchIDCurrentSet'
9+
| 'kSecAccessControlUserPresence'
10+
| 'kSecAccessControlBiometryAny'
11+
| 'kSecAccessControlBiometryCurrentSet';
1212

1313
type RNSensitiveInfoAttrAccessibleOptions =
14-
| "kSecAttrAccessibleAfterFirstUnlock"
15-
| "kSecAttrAccessibleAlways"
16-
| "kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly"
17-
| "kSecAttrAccessibleWhenUnlockedThisDeviceOnly"
18-
| "kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly"
19-
| "kSecAttrAccessibleAlwaysThisDeviceOnly"
20-
| "kSecAttrAccessibleWhenUnlocked";
14+
| 'kSecAttrAccessibleAfterFirstUnlock'
15+
| 'kSecAttrAccessibleAlways'
16+
| 'kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly'
17+
| 'kSecAttrAccessibleWhenUnlockedThisDeviceOnly'
18+
| 'kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly'
19+
| 'kSecAttrAccessibleAlwaysThisDeviceOnly'
20+
| 'kSecAttrAccessibleWhenUnlocked';
2121

2222
interface RNSensitiveInfoAndroidDialogStrings {
2323
header?: string;
@@ -45,11 +45,11 @@ export interface RNSensitiveInfoOptions {
4545
export declare function setItem(
4646
key: string,
4747
value: string,
48-
options: RNSensitiveInfoOptions
48+
options: RNSensitiveInfoOptions,
4949
): Promise<null>;
5050
export declare function getItem(
5151
key: string,
52-
options: RNSensitiveInfoOptions
52+
options: RNSensitiveInfoOptions,
5353
): Promise<string>;
5454

5555
interface SensitiveInfoEntry {
@@ -58,12 +58,12 @@ interface SensitiveInfoEntry {
5858
service: string;
5959
}
6060
export declare function getAllItems(
61-
options: RNSensitiveInfoOptions
61+
options: RNSensitiveInfoOptions,
6262
): Promise<[SensitiveInfoEntry[]]>;
6363

6464
export declare function deleteItem(
6565
key: string,
66-
options: RNSensitiveInfoOptions
66+
options: RNSensitiveInfoOptions,
6767
): Promise<null>;
6868
export declare function isSensorAvailable(): Promise<
6969
RNSensitiveInfoBiometryType | boolean

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"rollup": "^2.23.0",
5858
"rollup-plugin-peer-deps-external": "^2.2.3",
5959
"rollup-plugin-typescript2": "^0.27.1",
60-
"typescript": "^3.9.7"
60+
"typescript": "^3.9.7",
61+
"yalc": "^1.0.0-pre.40"
6162
}
6263
}

yalc.lock

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)