【问题标题】:Ionic 3 Firebase can't access redirect result dataIonic 3 Firebase 无法访问重定向结果数据
【发布时间】:2018-01-07 13:34:41
【问题描述】:

我正在开发一个 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);
    });
}

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

【问题讨论】:

  • 您确定吗。您没有遇到任何错误吗?
  • @NakulKundaliya 如果有一个错误我真的看不到它,日志也是空的......
  • 请注意,如果我使用弹出式登录方法,它会起作用。

标签: typescript firebase firebase-authentication ionic3 angularfire2


【解决方案1】:

你可以使用我的代码。

导入 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 => {  });

我希望它对你有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-30
    • 1970-01-01
    • 2019-03-21
    • 2017-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多