离子Facebook身份验证重定向问题 [英] Ionic Facebook Authentication Redirection Problem

查看:116
本文介绍了离子Facebook身份验证重定向问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我逐步按照本教程操作 https://ionicthemes.com/tutorials/关于/ionic-facebook-login

I followed this tutorial step by step https://ionicthemes.com/tutorials/about/ionic-facebook-login

我遇到的问题是,登录后,我的应用程序没有重定向到我需要的页面.在运行Android 9的模拟Pixel 2设备上进行测试时,控制台上没有错误.这是用于处理身份验证的代码:

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 => {
    this.uid = response.authResponse.userID;
    this.facebook.api('/me?fields=name,email', permissions)
    .then(user => {
    user.picture = 'https://graph.facebook.com/' + userId + 
    '/picture?type=large';
    this.dataService.getUser(this.uid).subscribe((data) => {
      if (data.data() !== undefined) {
        if (data.data().isNew) {
          this.zone.run(() => {
            this.router.navigate(['/profile']);
          });
        } else {
          this.zone.run(() => {
            this.router.navigate(['/home']);
          });
        }
      } else {
        this.dataService.addUser(....)}).then(() => {
          this.zone.run(() => {
            this.router.navigate(['/profile']);
        });
       }
     });
    });

我希望登录成功后,可以使用路由器角度组件正确重定向应用程序.

I expect that after login success the app is redirected correctly using the router angular component.

推荐答案

问题原因

我认为问题与我的Angular Fire Auth Observable有关:

Problem cause

I figured the problem was related to my Angular Fire Auth Observable:

this.afAuth.auth.onAuthStateChanged((user) => {
              console.log('user state:', user);
              if (user) {
                this.fireUser = user;
                this.deviceStorage.set('uid', user.uid);
                this.dataService.userNewListener(user.uid);
              } else {
                    this.deviceStorage.set('uid', '');
                    this.router.navigate(['/login']);
              }
});

由于我使用的是可观察的不变的本地解决方案(facebook cordova插件),因为它将我重定向回登录.

Since I'm using a native solution (facebook cordova plugin) that observable doesn't change, since it was redirecting me back to login.

解决方案是,在使用插件成功执行登录后,我可以使用响应访问令牌作为凭证来继续进行操作,并使用AngularFire进行登录:

The solution was that after I successfully perform the login using the plugin, I could use the response access token as a credential to proceed and sign in with it using AngularFire:

this.facebook.login(permissions).then(response => {

    const facebookCredential = firebase.auth.FacebookAuthProvider.credential(response.authResponse.accessToken);
    this.afAuth.auth.signInWithCredential(facebookCredential).then(() => {
              console.log('navigating profile');
              this.router.navigate(['/profile']);
    });
});

这篇关于离子Facebook身份验证重定向问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆