diff --git a/index.js b/index.js index 9b73932..68dfc75 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,7 @@ */ import { AppRegistry } from 'react-native'; -import App from './App'; +import App from './src/screen/authorised/AuthScreen.tsx'; import { name as appName } from './app.json'; AppRegistry.registerComponent(appName, () => App); diff --git a/src/screen/authorised/AuthScreen.tsx b/src/screen/authorised/AuthScreen.tsx new file mode 100644 index 0000000..b9024be --- /dev/null +++ b/src/screen/authorised/AuthScreen.tsx @@ -0,0 +1,35 @@ +import React from 'react'; +import { View, Text, TouchableOpacity, Alert } from 'react-native'; +import { authenticateWithDeviceLock } from './deviceAuth'; + +const AuthScreen = () => { + const handleAuth = async () => { + const result = await authenticateWithDeviceLock(); + + if (result.success) { + Alert.alert('Success', 'User authenticated'); + // 👉 Navigate to Home / Unlock app + } else { + Alert.alert('Failed', result.message); + } + }; + + return ( + + + + Unlock with Device Lock + + + + ); +}; + +export default AuthScreen; diff --git a/src/screen/authorised/deviceAuth.ts b/src/screen/authorised/deviceAuth.ts new file mode 100644 index 0000000..fe77972 --- /dev/null +++ b/src/screen/authorised/deviceAuth.ts @@ -0,0 +1,40 @@ +import ReactNativeBiometrics from 'react-native-biometrics'; + +const rnBiometrics = new ReactNativeBiometrics({ + allowDeviceCredentials: true, // 👈 IMPORTANT (PIN / Pattern) +}); + +export const authenticateWithDeviceLock = async () => { + try { + const { available } = await rnBiometrics.isSensorAvailable(); + + if (!available) { + return { + success: false, + message: 'Device lock is not available', + }; + } + + const result = await rnBiometrics.simplePrompt({ + promptMessage: 'Authenticate to continue', + cancelButtonText: 'Cancel', + }); + + if (result.success) { + return { + success: true, + message: 'Authentication successful', + }; + } else { + return { + success: false, + message: 'Authentication cancelled', + }; + } + } catch (error: any) { + return { + success: false, + message: error?.message || 'Authentication failed', + }; + } +};