Update example app with biometric features
This commit is contained in:
parent
0b1b1d3395
commit
8a30ba0341
|
@ -25,42 +25,60 @@ export default class KeychainExample extends Component {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
save() {
|
async save() {
|
||||||
Keychain.setGenericPassword(this.state.username, this.state.password)
|
try {
|
||||||
.then(() => {
|
if (this.state.biometryType) {
|
||||||
this.setState({ status: 'Credentials saved!' });
|
await Keychain.setPasswordWithAuthentication(
|
||||||
})
|
this.state.username,
|
||||||
.catch(err => {
|
this.state.password,
|
||||||
this.setState({ status: 'Could not save credentials, ' + err });
|
{
|
||||||
});
|
accessControl:
|
||||||
|
Keychain.ACCESS_CONTROL.TOUCH_ID_ANY_OR_DEVICE_PASSCODE,
|
||||||
|
authenticationType: Keychain.AUTHENTICATION_TYPE.BIOMETRICS,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
await Keychain.setGenericPassword(
|
||||||
|
this.state.username,
|
||||||
|
this.state.password
|
||||||
|
);
|
||||||
|
}
|
||||||
|
this.setState({ status: 'Credentials saved!' });
|
||||||
|
} catch (err) {
|
||||||
|
this.setState({ status: 'Could not save credentials, ' + err });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
load() {
|
async load() {
|
||||||
Keychain.getGenericPassword()
|
try {
|
||||||
.then(credentials => {
|
const credentials = await (this.state.biometryType
|
||||||
if (credentials) {
|
? Keychain.getPasswordWithAuthentication({
|
||||||
this.setState({ ...credentials, status: 'Credentials loaded!' });
|
accessControl:
|
||||||
} else {
|
Keychain.ACCESS_CONTROL.TOUCH_ID_ANY_OR_DEVICE_PASSCODE,
|
||||||
this.setState({ status: 'No credentials stored.' });
|
authenticationType: Keychain.AUTHENTICATION_TYPE.BIOMETRICS,
|
||||||
}
|
})
|
||||||
})
|
: Keychain.getGenericPassword());
|
||||||
.catch(err => {
|
if (credentials) {
|
||||||
this.setState({ status: 'Could not load credentials. ' + err });
|
this.setState({ ...credentials, status: 'Credentials loaded!' });
|
||||||
});
|
} else {
|
||||||
|
this.setState({ status: 'No credentials stored.' });
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
this.setState({ status: 'Could not load credentials. ' + err });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
reset() {
|
async reset() {
|
||||||
Keychain.resetGenericPassword()
|
try {
|
||||||
.then(() => {
|
await Keychain.resetGenericPassword();
|
||||||
this.setState({
|
this.setState({
|
||||||
status: 'Credentials Reset!',
|
status: 'Credentials Reset!',
|
||||||
username: '',
|
username: '',
|
||||||
password: '',
|
password: '',
|
||||||
});
|
|
||||||
})
|
|
||||||
.catch(err => {
|
|
||||||
this.setState({ status: 'Could not reset credentials, ' + err });
|
|
||||||
});
|
});
|
||||||
|
} catch (err) {
|
||||||
|
this.setState({ status: 'Could not reset credentials, ' + err });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|
Loading…
Reference in New Issue