Skip to content

Commit

Permalink
Biometric authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
Isthisanmol committed Apr 4, 2024
1 parent 5df27b7 commit f26df48
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 6 deletions.
2 changes: 2 additions & 0 deletions apps/expo/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.USE_BIOMETRIC" />
<uses-permission android:name="android.permission.USE_FINGERPRINT" />
<queries>
<intent>
<action android:name="android.intent.action.VIEW"/>
Expand Down
87 changes: 81 additions & 6 deletions apps/expo/app/_layout.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,89 @@
import { Provider } from 'app/provider';
import { Stack } from 'expo-router';
import * as LocalAuthentication from 'expo-local-authentication';
import { useState, useEffect } from "react";
import { Alert, Button, StyleSheet, Text, View } from "react-native";

export default function HomeLayout() {

const [authenticated, setAuthenticated] = useState(false);



const checkDeviceForHardware = async () => {
let compatible = await LocalAuthentication.hasHardwareAsync();
console.log("compatible", compatible);
};

const checkForBiometrics = async () => {
let biometricRecords = await LocalAuthentication.isEnrolledAsync();
console.log("biometricRecords", biometricRecords);
};

const authenticate = async () => {
let result = await LocalAuthentication.authenticateAsync();
if (result.success) {
setAuthenticated(true);
} else {
Alert.alert("Authentication failed");
}
};

useEffect(()=> {
checkDeviceForHardware();
checkForBiometrics();
authenticate();
}, [])




return (
<Provider>
<Stack
screenOptions={{
headerShown: false,
}}
/>
{/* <View style={styles.container}>
<Text style={styles.heading}>
Biometric Authentication
</Text>
<Button
title={authenticated ? "Hide Content" : "Show Hidden Content"}
onPress={() => {
if (authenticated) {
setAuthenticated(false);
return;
}
checkDeviceForHardware();
checkForBiometrics();
authenticate();
}}
/>
{authenticated && ( */}
<Stack
screenOptions={{
headerShown: false,
}}
/>

{/* )}
</View> */}
</Provider>
);
);
}

// const styles = StyleSheet.create({
// container: {
// backgroundColor: "transparent",
// flex: 1,
// justifyContent: "space-evenly",
// alignItems: "center",

// },
// heading: {
// fontSize: 20,
// fontWeight: "bold",
// marginBottom: 20,
// color: "green",
// },
// });
1 change: 1 addition & 0 deletions apps/expo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"expo-image-picker": "^14.7.1",
"expo-linear-gradient": "~12.3.0",
"expo-linking": "~5.0.2",
"expo-local-authentication": "~13.4.1",
"expo-location": "~16.1.0",
"expo-random": "~13.2.0",
"expo-router": "^2.0.9",
Expand Down
Empty file.
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17220,6 +17220,7 @@ __metadata:
expo-image-picker: "npm:^14.7.1"
expo-linear-gradient: "npm:~12.3.0"
expo-linking: "npm:~5.0.2"
expo-local-authentication: "npm:~13.4.1"
expo-location: "npm:~16.1.0"
expo-random: "npm:~13.2.0"
expo-router: "npm:^2.0.9"
Expand Down Expand Up @@ -17469,6 +17470,17 @@ __metadata:
languageName: node
linkType: hard

"expo-local-authentication@npm:~13.4.1":
version: 13.4.1
resolution: "expo-local-authentication@npm:13.4.1"
dependencies:
invariant: "npm:^2.2.4"
peerDependencies:
expo: "*"
checksum: 10/2b002b3061ae3c234a6de54bf1f7b86b8c89b23707213dec54c630e31475abda15cdfced3beb737771859c320e89a2d56754b581941d3c5511dd2d734b1550a9
languageName: node
linkType: hard

"expo-location@npm:~16.1.0":
version: 16.1.0
resolution: "expo-location@npm:16.1.0"
Expand Down

0 comments on commit f26df48

Please sign in to comment.