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

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)

Dou*_*son 5

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

您似乎将 javascript 客户端 SDK 与 Admin SDK 混为一谈。没有理由在 Cloud Functions 中使用客户端 SDK。它应该只在浏览器中使用,因为登录只在用户实际使用的设备上有意义。

  • 如果我们想使用云函数创建一个完整的 REST API 服务,在这种情况下可以做什么?如您所见,我们是否需要到达终点,我们可以从任何其他客户端请求。我们如何在不使用任何 Firebase Client SDK 的情况下解决登录问题? (7认同)