I followed this tutorial step by step https://ionicthemes.com/tutorials/about/ionic-facebook-login
The issue I’m having is that after the login, my app is not redirecting to the page I need it to. No error on the console when testing this on an emulated Pixel 2 device running Android 9 . Here’s the code for handling the authentication:
const permissions = ['public_profile', 'email'];
await this.facebook.login(permissions).then(response => {
const userId = response.authResponse.userID;
this.uid = userId;
this.facebook.api('/me?fields=name,email', permissions)
.then(user => {
user.picture = 'https://graph.facebook.com/' + userId + '/picture?type=large';
const email = user.email;
this.dataService.getUser(this.uid).subscribe((data) => {
if (data.data() !== undefined) {
this.user = data.data();
this.deviceStorage.set('user', JSON.stringify(data.data()));
this.deviceStorage.set('uid', this.uid);
this.dataService.userNewListener(this.uid);
if (data.data().isNew) {
this.zone.run(() => {
this.router.navigate(['/profile']);
});
this.toastService.showToast('Please set up your profile first.');
} else {
this.zone.run(() => {
this.router.navigate(['/home']);
});
this.toastService.showToast('User has signed in successfully.');
}
} else {
this.dataService.addUser(this.uid, {email, uid: this.uid, isNew: true, isFb: true}).then(() => {
const obj = {email, uid: this.uid, isNew: true, isFb: true};
this.deviceStorage.set('uid', this.uid);
this.deviceStorage.set('user', JSON.stringify(obj));
this.toastService.showToast('Please set up your profile first.');
this.zone.run(() => {
this.router.navigate(['/profile']);
});
}).catch((err) => { console.log('facebookNerror 3 :' + err); });
}
});
}).catch((err) => { console.log('facebookNerror 2 :' + err); });
}, error => {
console.log(error);
}).catch((err) => {
console.log('facebookNerror 1 :' + err);
this.toastService.showToast('Native facebook error:');
this.toastService.showToast('Native facebook error:' + err);
});