React native Schlüsselkettenfehler- Eigenschaft kann nicht gelesen werden 'setgenericpasswordForoptions' von null
Posted: 12 Feb 2025, 02:30
Ich muss nach dem Anmeldungsprozess eine Gesichts -ID in iOS und Fingerabdruck in Android implementieren. Mittel, ich benötige die App, um zuerst nach Face ID -Erkennungsfunktion im Gerät zu überprüfen. Wenn diese Funktion nicht verfügbar ist, sollte sie nach der Erkennung von Fingerabdrücken überprüfen. Durch eine dieser Methoden sollte die App die Authentifizierung einrichten - das Gerät sollte die Anmeldeinformationen auf dem Gerät auf dem Gerätetastatur verschlüsselt. erfolgreich und ich lasse das Alarmkonto erfolgreich erstellen! Dann zeigt es das Popup, in dem gefragt wird: "Möchten Sie die Authentifizierung von FaceId/ Fingerabdruck aktivieren?". Wenn Sie auf Ja klicken, wird der Fingerabdrucksensor im Android -Telefon geöffnet. Nachdem ich meinen Finger am Sensor behalten hatte, habe ich die Fehleralarm "keine Gesichtsausweise aktivieren. Bitte stellen Sie sicher, dass er auf Ihrem Gerät eingerichtet ist." gemäß der Fehleralarm in meinem Anmeldebildschirm. Gleiches gilt auch für das iPhone. < /P>
biometricAuth.js
SignUpScreen.js
Ich habe Expo-Local-Authentication Paket & React-Native-Keychain installiert. Schritte zur Fehlerbehebung wie Deinstallieren und Neuinstallieren von Abhängigkeiten, Löschen von Cache und Wiederaufbau von App usw.>
Code: Select all
>
> Error : //console messages (android phone)
(NOBRIDGE) LOG Biometric hardware available: true
> (NOBRIDGE) LOG Biometrics enrolled: true
> (NOBRIDGE) LOG Supported biometric types: [1]
> (NOBRIDGE) LOG Biometric hardware available: true
> (NOBRIDGE) LOG Biometrics enrolled: true
> (NOBRIDGE) LOG Supported biometric types: [1]
> (NOBRIDGE) ERROR Biometric setup failed: [TypeError: Cannot read property 'setGenericPasswordForOptions' of null]
> (NOBRIDGE) ERROR Biometric setup error: [TypeError: Cannot read property 'setGenericPasswordForOptions' of null]
> //console messages (ios phone)
> (NOBRIDGE) LOG Biometric hardware available: true
> (NOBRIDGE) LOG Biometrics enrolled: true
> (NOBRIDGE) LOG Supported biometric types: [2]
> (NOBRIDGE) LOG Biometric hardware available: true
> (NOBRIDGE) LOG Biometrics enrolled: true
> (NOBRIDGE) LOG Supported biometric types: [2]
> (NOBRIDGE) ERROR Biometric setup failed: [TypeError: Cannot read property 'setGenericPasswordForOptions' of null]
> (NOBRIDGE) ERROR Biometric setup error: [TypeError: Cannot read property 'setGenericPasswordForOptions' of null]
Code: Select all
import * as LocalAuthentication from 'expo-local-authentication';
import * as Keychain from 'react-native-keychain';
import { Platform } from 'react-native';
export const BiometricAuth = {
// Check what type of biometric authentication is available
checkBiometricSupport: async () => {
try {
const compatible = await LocalAuthentication.hasHardwareAsync();
console.log('Biometric hardware available:', compatible);
if (!compatible) {
return {
supported: false,
error: 'No biometric hardware available on this device.'
};
}
const enrolled = await LocalAuthentication.isEnrolledAsync();
console.log('Biometrics enrolled:', enrolled);
if (!enrolled) {
return {
supported: false,
error: 'No biometrics have been enrolled on this device.'
};
}
const types = await LocalAuthentication.supportedAuthenticationTypesAsync();
console.log('Supported biometric types:', types);
const hasFaceId = types.includes(LocalAuthentication.AuthenticationType.FACIAL_RECOGNITION);
const hasFingerprint = types.includes(LocalAuthentication.AuthenticationType.FINGERPRINT);
return {
supported: true,
faceIdAvailable: hasFaceId,
fingerprintAvailable: hasFingerprint,
preferredMethod: hasFaceId ? 'faceId' : hasFingerprint ? 'fingerprint' : null
};
} catch (error) {
console.error('Biometric support check failed:', error);
return {
supported: false,
error: error.message
};
}
},
// Enable biometric authentication and store credentials
enableBiometric: async (username, password) => {
try {
const biometricSupport = await BiometricAuth.checkBiometricSupport();
if (!biometricSupport.supported) {
throw new Error('Biometric authentication is not available on this device');
}
// Set appropriate prompt message based on available method
const promptMessage = Platform.select({
ios: biometricSupport.faceIdAvailable ? 'Enable Face ID login' : 'Enable Touch ID login',
android: 'Enable fingerprint login',
default: 'Enable biometric login'
});
// Authenticate with available biometric method
const result = await LocalAuthentication.authenticateAsync({
promptMessage,
disableDeviceFallback: false, // Allow fallback to device passcode
fallbackLabel: 'Use passcode' // Label for fallback button
});
if (result.success) {
// Store credentials in keychain
await Keychain.setGenericPassword(username, password);
return true;
}
return false;
} catch (error) {
console.error('Biometric setup failed:', error);
throw error;
}
},
// Authenticate using biometrics and retrieve credentials
authenticateWithBiometric: async () => {
try {
const biometricSupport = await BiometricAuth.checkBiometricSupport();
if (!biometricSupport.supported) {
throw new Error('Biometric authentication is not available');
}
const promptMessage = Platform.select({
ios: biometricSupport.faceIdAvailable ? 'Log in with Face ID' : 'Log in with Touch ID',
android: 'Log in with fingerprint',
default: 'Log in with biometrics'
});
const result = await LocalAuthentication.authenticateAsync({
promptMessage,
disableDeviceFallback: false,
fallbackLabel: 'Use passcode'
});
if (result.success) {
const credentials = await Keychain.getGenericPassword();
if (credentials) {
return {
success: true,
username: credentials.username,
password: credentials.password
};
}
throw new Error('No credentials stored');
}
return { success: false };
} catch (error) {
console.error('Biometric authentication failed:', error);
throw error;
}
},
// Remove stored biometric credentials
removeBiometric: async () => {
try {
await Keychain.resetGenericPassword();
return true;
} catch (error) {
console.error('Failed to remove biometric credentials:', error);
throw error;
}
}
};
< /code>
**androidManifest.xml ** < /p>
Code: Select all
import { BiometricAuth } from "../components/BiometricAuth";
const enableBiometric = async () => {
try {
const success = await BiometricAuth.enableBiometric(userName, password);
if (success) {
Alert.alert(
"Success",
`${biometricType === 'faceId' ? 'Face ID' : 'Fingerprint'} has been enabled successfully!`
);
setBiometricVisible(false);
} else {
Alert.alert("Error", "Failed to enable biometric authentication. Please try again.");
}
} catch (error) {
console.error("Biometric setup error:", error);
Alert.alert(
"Error",
"Could not enable biometric authentication. Please ensure it is set up on your device."
);
}
};