Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
});
}