Ionic 3 Firebase无法访问重定向结果数据

时间:2017-07-31 20:48:21

标签: typescript firebase firebase-authentication ionic3 angularfire2

我正在研究Ionic 3应用程序,我遇到firebase.auth().getRedirectResult()函数的小问题。看起来它不能访问then函数。我试图控制日志结果,但它没有出现在控制台中,也没有string的随机控制台日志。我在那里做错了吗?

以下是代码:

signInWithGoogle() {
    const provider = new firebase.auth.GoogleAuthProvider();

    return firebase.auth().signInWithRedirect(provider)
    .then(() => {
        firebase.auth().getRedirectResult()
        .then(data => {
            console.log(data); // Does not print this
            console.log('User signed in.'); // Neither this
        })
        .catch(error => {
            console.log(error);
            throw (error);
        });
    })
    .catch(error => {
        console.log(error);
        throw (error);
    });
}

它在控制台中没有记录任何内容,但它通过了身份验证。它成功登录帐户。

1 个答案:

答案 0 :(得分:0)

您可以使用我的代码。

导入Google plus依赖。

import { GooglePlus } from '@ionic-native/google-plus';

在登录功能中添加以下代码

this.googlePlus.login({
  'webClientId': ' ' // Your Google console id
}).then((success) => {
  console.log("===login with googlePlus==",success)
  Let credential = free-base. Auth. GoogleAuthProvider. credential (success ['idToken'], null);
  firebase.auth().signInWithCredential(credential)
    .then((success) => {
      console.log("=====success",success)
    })
    .catch((error) => {
      console.log("=====error",error)
      let code = error["code"];
    });
}, error => {  });

我希望它适合你。