gpt4 book ai didi

javascript - firebase.auth(...).signInWithEmailAndPassword 不是 Cloud Function 中的函数

转载 作者:行者123 更新时间:2023-11-29 20:57:09 26 4
gpt4 key购买 nike

我在调用函数时遇到错误。我正在使用 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!");
});

最佳答案

当您从 Admin SDK 调用 firebase.auth() 时,您将获得一个 Auth 类型的对象.正如您从 API 文档中看到的那样,它没有名为 signInWithEmailAndPassword 的方法。

您似乎混淆了 JavaScript 客户端 SDK 和 Admin SDK。没有理由在 Cloud Functions 中使用客户端 SDK。它应该仅在浏览器中使用,因为登录仅在用户实际使用的设备上才有意义。

关于javascript - firebase.auth(...).signInWithEmailAndPassword 不是 Cloud Function 中的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48706747/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com