Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'react-native-fingerprint-scanner' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
async defineDefaultAuthMethod() {
const { password } = await getPassphraseFromKeyChain();
let sensorType = null;
try {
sensorType = await FingerprintScanner.isSensorAvailable();
} catch (error) {
sensorType = null;
}
const signOut = this.props.navigation.getParam('signOut');
const delay = this.state.view === 'splash' && !signOut ? 1100 : 0;
// Update the store
this.props.settingsUpdated({
sensorType,
hasStoredPassphrase: !!password,
});
// Update the component state
this.timeout = setTimeout(() => {
if (password && sensorType) {
this.setState({
view: 'biometricAuth',
checkTouchIdSupport = async () => {
try {
const isSensorAvailable = await FingerprintScanner.isSensorAvailable();
if (isSensorAvailable) {
this.setState({
isTouchIdSupported: true,
});
this.onTouchIdClick();
}
} catch (error) {
// An error happened during biometric detection
}
};
async componentWillUnmount () {
try {
await FingerprintScanner.release()
} catch (err) { /* Do nothing */ }
}
componentWillUnmount() { // eslint-disable-line
FingerprintScanner.release();
}
it("passes when used properly", () => {
FingerprintScanner.authenticate({
description: "Any string",
fallbackEnabled: true
});
FingerprintScanner.authenticate({
description: "Any string"
});
FingerprintScanner.authenticate({
fallbackEnabled: true
});
});
it("passes when used properly", () => {
FingerprintScanner.isSensorAvailable().then(type => {
(type: "Fingerprint" | "Face ID" | "Touch ID");
});
});
});
it("passes when used properly", () => {
(FingerprintScanner.release(): void);
});
});
async componentDidMount () {
if (!this.props.isLocked) {
this.props.history.push('/dashboard')
return
}
try {
let isAvailable = await FingerprintScanner.isSensorAvailable()
if (!isAvailable) {
this.setState({ sensorAvail: isAvailable })
} else {
await FingerprintScanner.authenticate({ onAttempt: this.setError })
await this.setState({ isError: false })
setTimeout(this.goBack, 400)
}
} catch (err) {
this.setError(err)
}
}
errorCallback = err => err,
description,
androidError,
}) => {
const authConfig =
Platform.OS === 'ios'
? {
description:
description ||
'Scan your fingerprint on the device scanner to sign in',
}
: { onAttempt: androidError };
try {
await FingerprintScanner.isSensorAvailable();
try {
await FingerprintScanner.authenticate(authConfig);
successCallback();
} catch (error) {
errorCallback(error);
}
} catch (error) {
errorCallback(error);
}
};
componentDidMount() {
FingerprintScanner
.authenticate({ description: 'Scan your fingerprint on the device scanner to continue' })
.then(() => {
this.props.handlePopupDismissed();
AlertIOS.alert('Authenticated successfully');
})
.catch((error) => {
this.props.handlePopupDismissed();
AlertIOS.alert(error.message);
});
}