无法登录使用 Node js 和 firebase-admin 创建的新用户

问题描述 投票:0回答:1

目标:创建用户并登录。就这么简单。

我使用 inf nodejs 和 firebase-admin 创建了用户,其标准功能运行良好:

createUser: function (fullName, email, password) {
        return new Promise(function (resolve, reject) {
            firebase.auth().createUser({
                    email: email,
                    emailVerified: false,
                    password: password,
                    displayName: fullName,
                    disabled: false
                }).then(function(userRecord) {
                    resolve(userRecord);
                    console.log('Successfully created new user:', userRecord.uid);
                }).catch(function(error) {
                    resolve({res: 'error', error});
                    console.log('Error creating new user:', error);
                });
        })
    },

当我调试时,用户是在 firebase 身份验证和我的数据库中创建的,并且我使用 firebase 文档中的简单 POST

const signInUrl = `https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=${apiKey}`;
                const requestData = {
                    email: values.email,
                    password: values.password,
                    returnSecureToken: true,
                }
                
                fetch(signInUrl, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify(requestData),
                })

不知何故,当我手动创建帐户时可以工作,但如果我使用节点js中的 firebase-admin 则不行

这是我尝试登录后在客户端收到的响应 { “错误”: { “代码”:400, “消息”:“INVALID_LOGIN_CREDENTIALS”, “错误”:[ { “消息”:“INVALID_LOGIN_CREDENTIALS”, “域”:“全球”, “原因”:“无效” } ] } } 所有代码均已调试,所有变量和参数都正常

reactjs node.js firebase-authentication firebase-admin
1个回答
0
投票

有时事情的运作方式令人印象深刻。经过两天的努力解决我的问题后,我意识到 Firebase 文档中没有有关使用 REST API 的信息,因此如果您使用 firebase-admin 创建帐户,则无法在客户端中登录此帐户。好吧我的问题: 为什么 Firebase 在 firebase-admin 中有一个创建帐户方法?

© www.soinside.com 2019 - 2024. All rights reserved.