Phecda

feat: add biometrics auth

@@ -27,6 +27,7 @@ @@ -27,6 +27,7 @@
27 <!-- <uses-permission android:name="android.permission.RECEIVE_WAP_PUSH" />--> 27 <!-- <uses-permission android:name="android.permission.RECEIVE_WAP_PUSH" />-->
28 <!-- <uses-permission android:name="android.permission.RECORD_AUDIO" />--> 28 <!-- <uses-permission android:name="android.permission.RECORD_AUDIO" />-->
29 <!-- <uses-permission android:name="android.permission.SEND_SMS" />--> 29 <!-- <uses-permission android:name="android.permission.SEND_SMS" />-->
  30 + <uses-permission android:name="android.permission.USE_BIOMETRIC" />
30 <!-- <uses-permission android:name="android.permission.USE_SIP" />--> 31 <!-- <uses-permission android:name="android.permission.USE_SIP" />-->
31 <!-- <uses-permission android:name="android.permission.WRITE_CALENDAR" />--> 32 <!-- <uses-permission android:name="android.permission.WRITE_CALENDAR" />-->
32 <!-- <uses-permission android:name="android.permission.WRITE_CALL_LOG" />--> 33 <!-- <uses-permission android:name="android.permission.WRITE_CALL_LOG" />-->
@@ -2,10 +2,10 @@ @@ -2,10 +2,10 @@
2 2
3 buildscript { 3 buildscript {
4 ext { 4 ext {
5 - buildToolsVersion = "28.0.3" 5 + buildToolsVersion = "29.0.2"
6 minSdkVersion = 16 6 minSdkVersion = 16
7 - compileSdkVersion = 28 7 + compileSdkVersion = 29
8 - targetSdkVersion = 28 8 + targetSdkVersion = 29
9 } 9 }
10 repositories { 10 repositories {
11 google() 11 google()
@@ -52,6 +52,8 @@ @@ -52,6 +52,8 @@
52 </dict> 52 </dict>
53 <key>NSCameraUsageDescription</key> 53 <key>NSCameraUsageDescription</key>
54 <string>Use your camera to take a photo or scan codes</string> 54 <string>Use your camera to take a photo or scan codes</string>
  55 + <key>NSFaceIDUsageDescription</key>
  56 + <string>Allow you a quick and secure access</string>
55 <key>NSLocationWhenInUseUsageDescription</key> 57 <key>NSLocationWhenInUseUsageDescription</key>
56 <string>Use your location to check security</string> 58 <string>Use your location to check security</string>
57 <key>NSPhotoLibraryAddUsageDescription</key> 59 <key>NSPhotoLibraryAddUsageDescription</key>
@@ -249,6 +249,8 @@ PODS: @@ -249,6 +249,8 @@ PODS:
249 - React 249 - React
250 - react-native-code (1.0.0-1): 250 - react-native-code (1.0.0-1):
251 - React 251 - React
  252 + - react-native-fingerprint-scanner (4.0.0):
  253 + - React
252 - react-native-netinfo (5.7.1): 254 - react-native-netinfo (5.7.1):
253 - React 255 - React
254 - react-native-safe-area-context (0.7.3): 256 - react-native-safe-area-context (0.7.3):
@@ -381,6 +383,7 @@ DEPENDENCIES: @@ -381,6 +383,7 @@ DEPENDENCIES:
381 - React-jsinspector (from `../node_modules/react-native/ReactCommon/jsinspector`) 383 - React-jsinspector (from `../node_modules/react-native/ReactCommon/jsinspector`)
382 - react-native-camera (from `../node_modules/react-native-camera`) 384 - react-native-camera (from `../node_modules/react-native-camera`)
383 - "react-native-code (from `../node_modules/@phecdas/react-native-code`)" 385 - "react-native-code (from `../node_modules/@phecdas/react-native-code`)"
  386 + - react-native-fingerprint-scanner (from `../node_modules/react-native-fingerprint-scanner`)
384 - "react-native-netinfo (from `../node_modules/@react-native-community/netinfo`)" 387 - "react-native-netinfo (from `../node_modules/@react-native-community/netinfo`)"
385 - react-native-safe-area-context (from `../node_modules/react-native-safe-area-context`) 388 - react-native-safe-area-context (from `../node_modules/react-native-safe-area-context`)
386 - react-native-webview (from `../node_modules/react-native-webview`) 389 - react-native-webview (from `../node_modules/react-native-webview`)
@@ -466,6 +469,8 @@ EXTERNAL SOURCES: @@ -466,6 +469,8 @@ EXTERNAL SOURCES:
466 :path: "../node_modules/react-native-camera" 469 :path: "../node_modules/react-native-camera"
467 react-native-code: 470 react-native-code:
468 :path: "../node_modules/@phecdas/react-native-code" 471 :path: "../node_modules/@phecdas/react-native-code"
  472 + react-native-fingerprint-scanner:
  473 + :path: "../node_modules/react-native-fingerprint-scanner"
469 react-native-netinfo: 474 react-native-netinfo:
470 :path: "../node_modules/@react-native-community/netinfo" 475 :path: "../node_modules/@react-native-community/netinfo"
471 react-native-safe-area-context: 476 react-native-safe-area-context:
@@ -554,6 +559,7 @@ SPEC CHECKSUMS: @@ -554,6 +559,7 @@ SPEC CHECKSUMS:
554 React-jsinspector: f74a62727e5604119abd4a1eda52c0a12144bcd5 559 React-jsinspector: f74a62727e5604119abd4a1eda52c0a12144bcd5
555 react-native-camera: 1b52abea404d04e040edb3e74b7c5523c01a3089 560 react-native-camera: 1b52abea404d04e040edb3e74b7c5523c01a3089
556 react-native-code: 8e0e693b36c1d928a9d00f8e90feb443c3e8aa15 561 react-native-code: 8e0e693b36c1d928a9d00f8e90feb443c3e8aa15
  562 + react-native-fingerprint-scanner: 03f3d966edacf2f515e361595b6778d3502db4fb
557 react-native-netinfo: 4fa023c153d582aeae8435df95c9a975c5986449 563 react-native-netinfo: 4fa023c153d582aeae8435df95c9a975c5986449
558 react-native-safe-area-context: e200d4433aba6b7e60b52da5f37af11f7a0b0392 564 react-native-safe-area-context: e200d4433aba6b7e60b52da5f37af11f7a0b0392
559 react-native-webview: 0633fd7861a9bd7a80bacaee7da763c3afc248fa 565 react-native-webview: 0633fd7861a9bd7a80bacaee7da763c3afc248fa
@@ -9,3 +9,4 @@ @@ -9,3 +9,4 @@
9 "NSLocationWhenInUseUsageDescription" = "为保证安全,需要定位"; 9 "NSLocationWhenInUseUsageDescription" = "为保证安全,需要定位";
10 "NSPhotoLibraryAddUsageDescription" = "向照片图库中添加照片"; 10 "NSPhotoLibraryAddUsageDescription" = "向照片图库中添加照片";
11 "NSPhotoLibraryUsageDescription" = "诸如扫码、设置头像等功能需要从照片图库中读取图片"; 11 "NSPhotoLibraryUsageDescription" = "诸如扫码、设置头像等功能需要从照片图库中读取图片";
  12 +"NSFaceIDUsageDescription" = "快速安全地支付";
@@ -31,6 +31,7 @@ @@ -31,6 +31,7 @@
31 "react-native-dark-mode": "^0.2.2", 31 "react-native-dark-mode": "^0.2.2",
32 "react-native-device-info": "^5.5.4", 32 "react-native-device-info": "^5.5.4",
33 "react-native-elements": "^1.2.7", 33 "react-native-elements": "^1.2.7",
  34 + "react-native-fingerprint-scanner": "https://github.com/Phecda/react-native-fingerprint-scanner#release",
34 "react-native-gesture-handler": "^1.6.1", 35 "react-native-gesture-handler": "^1.6.1",
35 "react-native-image-crop-picker": "^0.28.0", 36 "react-native-image-crop-picker": "^0.28.0",
36 "react-native-localize": "^1.4.0", 37 "react-native-localize": "^1.4.0",
@@ -3,12 +3,17 @@ import { BGScroll, Card, ListItem, Divider } from '../component/View'; @@ -3,12 +3,17 @@ import { BGScroll, Card, ListItem, Divider } from '../component/View';
3 import { useReduxDispatch, useReduxState } from '../store/hooks'; 3 import { useReduxDispatch, useReduxState } from '../store/hooks';
4 import { rootActions } from '../store'; 4 import { rootActions } from '../store';
5 import { Alert } from 'react-native'; 5 import { Alert } from 'react-native';
  6 +import BioAuth, {
  7 + Biometrics,
  8 + FingerprintScannerError,
  9 +} from 'react-native-fingerprint-scanner';
6 10
7 const LoginScreen = () => { 11 const LoginScreen = () => {
8 const { list, current } = useReduxState('user'); 12 const { list, current } = useReduxState('user');
9 const dispatch = useReduxDispatch(); 13 const dispatch = useReduxDispatch();
10 14
11 const [userName, setUserName] = useState(current?.name); 15 const [userName, setUserName] = useState(current?.name);
  16 + const [biometricType, setBiometricType] = useState<Biometrics>();
12 17
13 const onLogin = useCallback(() => { 18 const onLogin = useCallback(() => {
14 const newToken = userName ? 'yes!' + userName : 'no:('; 19 const newToken = userName ? 'yes!' + userName : 'no:(';
@@ -25,6 +30,23 @@ const LoginScreen = () => { @@ -25,6 +30,23 @@ const LoginScreen = () => {
25 dispatch(rootActions.userActions.setToken(newToken)); 30 dispatch(rootActions.userActions.setToken(newToken));
26 }, [userName, dispatch, list]); 31 }, [userName, dispatch, list]);
27 32
  33 + const authWithBio = useCallback(async () => {
  34 + try {
  35 + await BioAuth.authenticate({});
  36 + Alert.alert('Success');
  37 + } catch (err) {
  38 + const { message, name }: FingerprintScannerError = err;
  39 + Alert.alert(name, message);
  40 + }
  41 + BioAuth.release();
  42 + }, []);
  43 +
  44 + React.useEffect(() => {
  45 + BioAuth.isSensorAvailable()
  46 + .then(setBiometricType)
  47 + .catch(() => {});
  48 + }, []);
  49 +
28 return ( 50 return (
29 <BGScroll> 51 <BGScroll>
30 <Card round> 52 <Card round>
@@ -37,6 +59,15 @@ const LoginScreen = () => { @@ -37,6 +59,15 @@ const LoginScreen = () => {
37 /> 59 />
38 <Divider /> 60 <Divider />
39 <ListItem title="login" onPress={onLogin} /> 61 <ListItem title="login" onPress={onLogin} />
  62 + {!!biometricType && (
  63 + <>
  64 + <Divider />
  65 + <ListItem
  66 + title={`Auth with ${biometricType}`}
  67 + onPress={authWithBio}
  68 + />
  69 + </>
  70 + )}
40 </Card> 71 </Card>
41 </BGScroll> 72 </BGScroll>
42 ); 73 );
@@ -7109,6 +7109,10 @@ react-native-elements@^1.2.7: @@ -7109,6 +7109,10 @@ react-native-elements@^1.2.7:
7109 react-native-ratings "^6.3.0" 7109 react-native-ratings "^6.3.0"
7110 react-native-status-bar-height "^2.2.0" 7110 react-native-status-bar-height "^2.2.0"
7111 7111
  7112 +"react-native-fingerprint-scanner@https://github.com/Phecda/react-native-fingerprint-scanner#release":
  7113 + version "4.0.0"
  7114 + resolved "https://github.com/Phecda/react-native-fingerprint-scanner#98e1b397ff45985e243dc13318433bfd9c323fbd"
  7115 +
7112 react-native-gesture-handler@^1.6.1: 7116 react-native-gesture-handler@^1.6.1:
7113 version "1.6.1" 7117 version "1.6.1"
7114 resolved "https://registry.npm.taobao.org/react-native-gesture-handler/download/react-native-gesture-handler-1.6.1.tgz#678e2dce250ed66e93af409759be22cd6375dd17" 7118 resolved "https://registry.npm.taobao.org/react-native-gesture-handler/download/react-native-gesture-handler-1.6.1.tgz#678e2dce250ed66e93af409759be22cd6375dd17"