unable to get credentials from server
viharshitha opened this issue · comments
Hi Team,
The following code is what I used to build the app with Ionic and Capacitor, but I am unable to get credentials from the server. How do I specify the server name? When setting credentials, we set these values in keychain (iOS), but when I move the checked-in passwords, the saved credentials aren't visible.
code:
async ngOnInit() {
NativeBiometric.isAvailable().then(
async (result: AvailableResult) => {
const isAvailable = result.isAvailable;
alert('RESULT ' + JSON.stringify(result));
const isFaceId = result.biometryType === BiometryType.FACE_ID;
if (isAvailable) {
// Get user's credentials
await NativeBiometric.verifyIdentity({
reason: 'For easy log in',
title: 'Log in',
subtitle: 'Maybe add subtitle here?',
description: 'Maybe a description too?'
}).then(
async () => {
// Authentication successful
await NativeBiometric.getCredentials({
server: 'www.server.com'
}).then(
(credentials: Credentials) => {
alert('CREDENTIAL ' + JSON.stringify(credentials));
this.email = credentials.username;
this.password = credentials.password;
this.submit();
},
(error) => {
// Failed to authenticate
console.log('$$$$$$$Failed to authenticate');
}
);
},
(error) => {
// Failed to authenticate
console.log('$$$$$$$Failed to getCredentials', error);
}
);
}
},
(error) => {
// Couldn't check availability
}
);
}
submit function:
submit() {
if (Capacitor.getPlatform() === 'ios') {
SavePassword.promptDialog({
username: this.email,
password: this.password
});
}
this.authenticationError = false;
this.loading = true;
this.loader.show();
this.passwordinfo = this.password;
this.loginService.fetchAuthToken(this.email, this.password).subscribe(
(tokens) => {
NativeBiometric.setCredentials({
username: this.email,
password: this.password,
server: 'www.server.com'
}).then();
console.log('$$c setCredentials ', this.email, this.password);
})
I'm not sure I understand, if you could please walk me trough how this is supposed go? Are you running the submit function before ngOnInit is Called?