简体   繁体   中英

firebase.auth(...).signInWithEmailAndPassword is not a function in Cloud Function

I m getting Error while invoked function. I m using LsignInWithEmailAndPassword Method.Any Special Configuration is Require?

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!");
     });

When you call firebase.auth() from the Admin SDK, you're getting an object of type Auth . As you can see from the API docs, it doesn't have a method called signInWithEmailAndPassword .

It seems you're mixing up the javascript client SDK with the Admin SDK. There's no reason to use the client SDK in Cloud Functions. It's supposed to be used in the browser only, since signing in only makes sense on the device that the user is actually using.

signInWithEmailAndPassword is only available in a browser environment. To get access to who made a particular request, you can use firebase.auth().getToken to get a JWT token, and send that along to your cloud function endpoint. Then from there you can call verifyIdToken to get the uid of whoever made the request.

我遇到了同样的问题,但原因是我已经登录。我的错误是在注册后,我在我的个人资料中,我正在尝试登录。如果您收到此错误,请检查您是否是

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM