Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unable to get credentials from server #56

Open
viharshitha opened this issue May 5, 2022 · 1 comment
Open

unable to get credentials from server #56

viharshitha opened this issue May 5, 2022 · 1 comment

Comments

@viharshitha
Copy link

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);

})

@epicshaggy
Copy link
Owner

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants