Added OS-level authentication with optional App PIN / Offline PIN fallback
This commit is contained in:
35
src/screen/authorised/AuthScreen.tsx
Normal file
35
src/screen/authorised/AuthScreen.tsx
Normal file
@@ -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 (
|
||||
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
|
||||
<TouchableOpacity
|
||||
onPress={handleAuth}
|
||||
style={{
|
||||
backgroundColor: '#000',
|
||||
padding: 15,
|
||||
borderRadius: 8,
|
||||
}}
|
||||
>
|
||||
<Text style={{ color: '#fff', fontSize: 16 }}>
|
||||
Unlock with Device Lock
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
export default AuthScreen;
|
||||
40
src/screen/authorised/deviceAuth.ts
Normal file
40
src/screen/authorised/deviceAuth.ts
Normal file
@@ -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',
|
||||
};
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user