Rah*_*hul 5 javascript firebase google-cloud-functions firebase-admin
调用函数时出现错误。我正在使用 LsignInWithEmailAndPassword 方法。需要任何特殊配置吗?
const functions = require('firebase-functions');
const firebase=require('firebase-admin');
firebase.initializeApp(functions.config().firebase);
exports.login = functions.https.onRequest((request, response) => {
var data = {
email : 'demo@gmail.com',
password : 'demo123'
};
var auth = null;
firebase
.auth()
.signInWithEmailAndPassword(data.email, data.password)
.then( function(user){
response.send("Authenticated successfully with payload");
// console.log("Authenticated successfully with payload:", user);
auth = user;
})
.catch(function(error){
response.send("Login Failed!");
// console.log("Login Failed!", error);
});
// response.send("Hello from Firebase!");
});
Run Code Online (Sandbox Code Playgroud)
当您firebase.auth()从 Admin SDK调用时,您将获得一个Auth类型的对象。正如您从 API 文档中看到的那样,它没有名为signInWithEmailAndPassword.
您似乎将 javascript 客户端 SDK 与 Admin SDK 混为一谈。没有理由在 Cloud Functions 中使用客户端 SDK。它应该只在浏览器中使用,因为登录只在用户实际使用的设备上有意义。