Added OS-level authentication with optional App PIN / Offline PIN fallback

This commit is contained in:
mansi-dev
2026-01-15 23:07:06 +05:30
parent 250f9286d6
commit 9660a3267c
3 changed files with 76 additions and 1 deletions

View 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',
};
}
};