最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

app.auth(...)。signInWithCredential不是函数firebase错误

IT培训 admin 5浏览 0评论

app.auth(...)。signInWithCredential不是函数firebase错误

我正在尝试将Google登录名添加到我的Node js firebase应用程序中。我收到以下错误:app.auth(...)。signInWithCredential不是函数

这是服务器上的代码

    var credential = firebase.auth.GoogleAuthProvider.credential(id_token);
    return app.auth().signInWithCredential(credential);

在客户端上

 // We need to register an Observer on Firebase Auth to make sure auth is initialized.
        var unsubscribe = app.auth().onAuthStateChanged((firebaseUser) => {
            unsubscribe();
            // Check if we are already signed-in Firebase with the correct user.
            // Build Firebase credential with the Google ID token.
            var credential = firebase.auth.GoogleAuthProvider.credential(googleUser.getAuthResponse().id_token);
            // Sign in with credential from the Google user.
            firebase.auth().signInWithCredential(credential).catch( (error) => {
                // Handle Errors here.
                var errorCode = error.code;
                var errorMessage = error.message;
                // The email of the user's account used.
                var email = error.email;
                // The firebase.auth.AuthCredential type that was used.
                var credential = error.credential;
                console.dir(errorMessage);
            }).then( (success) => {
                console.dir(success);

                var id_token = googleUser.getAuthResponse().id_token;

                axios.post('/auth/google-login', {
                    id_token: id_token
                }).then(response => {
                    var result = response.data;
                    if (result.status === "ok") {
                        this.setState({complete: true});
                    } else if (result.error) {
                        this.setState({error: result.error});
                    }
                }).catch(error => {
                    console.dir(error);
                    this.setState({error: "error"});
                });
            });
        });

我做错了什么?

在nodejs文件的顶部,我有

var app = require('./base');

其中base:

var serviceAccount = require("./service-account-file.json");

const app =   fadmin.initializeApp({
    credential: fadmin.credential.cert(serviceAccount),
    databaseURL: ""
});
module.exports = app;
回答如下:

嗨,有迹象表明该问题始于节点版本6.21。那app.auth()。signInWithCredential(凭证)不工作

在v6.2.0中有效。

尝试signInWithEmailAndPassword使用最新版本的节点

app.auth(...)。signInWithCredential不是函数firebase错误

我正在尝试将Google登录名添加到我的Node js firebase应用程序中。我收到以下错误:app.auth(...)。signInWithCredential不是函数

这是服务器上的代码

    var credential = firebase.auth.GoogleAuthProvider.credential(id_token);
    return app.auth().signInWithCredential(credential);

在客户端上

 // We need to register an Observer on Firebase Auth to make sure auth is initialized.
        var unsubscribe = app.auth().onAuthStateChanged((firebaseUser) => {
            unsubscribe();
            // Check if we are already signed-in Firebase with the correct user.
            // Build Firebase credential with the Google ID token.
            var credential = firebase.auth.GoogleAuthProvider.credential(googleUser.getAuthResponse().id_token);
            // Sign in with credential from the Google user.
            firebase.auth().signInWithCredential(credential).catch( (error) => {
                // Handle Errors here.
                var errorCode = error.code;
                var errorMessage = error.message;
                // The email of the user's account used.
                var email = error.email;
                // The firebase.auth.AuthCredential type that was used.
                var credential = error.credential;
                console.dir(errorMessage);
            }).then( (success) => {
                console.dir(success);

                var id_token = googleUser.getAuthResponse().id_token;

                axios.post('/auth/google-login', {
                    id_token: id_token
                }).then(response => {
                    var result = response.data;
                    if (result.status === "ok") {
                        this.setState({complete: true});
                    } else if (result.error) {
                        this.setState({error: result.error});
                    }
                }).catch(error => {
                    console.dir(error);
                    this.setState({error: "error"});
                });
            });
        });

我做错了什么?

在nodejs文件的顶部,我有

var app = require('./base');

其中base:

var serviceAccount = require("./service-account-file.json");

const app =   fadmin.initializeApp({
    credential: fadmin.credential.cert(serviceAccount),
    databaseURL: ""
});
module.exports = app;
回答如下:

嗨,有迹象表明该问题始于节点版本6.21。那app.auth()。signInWithCredential(凭证)不工作

在v6.2.0中有效。

尝试signInWithEmailAndPassword使用最新版本的节点

发布评论

评论列表 (0)

  1. 暂无评论