我如何通过Firebase身份验证以及用户的电子邮件和密码来获取用户数据?
我能够捕获用户的唯一方法是使用
firebase.auth() function.getUserByEmail(email)
但是我找不到通过用户的电子邮件和密码进行通话的方法,对这个问题有帮助吗?
我的源代码:
var express = require('express');
var app = express();
const firebase = require('firebase-admin');
const inquirer = require('inquirer')
const serviceAccount = require('...')
var currentUser;
var userProfile;
var config = {
credential: firebase.credential.cert(serviceAccount),
apiKey: "...",
authDomain: "...",
databaseURL: "...",
projectId: "...",
storageBucket: "...",
messagingSenderId: "..."
};
firebase.initializeApp(config);
let server = app.listen('8081', function (err) {
if (err) {
console.log(err);
}
console.log("App listening on port " + "8081");
var authentication = [
{
type: 'input',
name: 'email',
message: "Type your email:",
},
{
type: 'password',
name: 'password',
message: "Type your password:",
},
]
inquirer.prompt(authentication).then(answers => {
console.log(`Hello! The application is starting!`)
startCrawler(answers['email'], answers['password'])
})
async () => {
await firebase.auth().getUserByEmail(email) //Here where I want to grab the user with email and password
.then((user) => {
currentUser = user.toJSON();
}).catch(err => {
console.log('Email or password invalid!');
});
if (!currentUser) { return };
}
});
答案 0 :(得分:1)
您似乎正在尝试使用Firebase Admin SDK在Node.js应用程序上登录用户。 Firebase Admin SDK没有登录用户的概念。如果需要,请考虑将常规Firebase SDK用于Web应用程序。
也请在这里查看我的答案:element size