简体   繁体   English

使用 Firebase 的云函数:signInWithEmailAndPassword 不是函数

[英]Cloud Functions with Firebase: signInWithEmailAndPassword is not a function

I'm beginning writing code with Cloud Functions with Firebase .我开始使用Cloud Functions 和 Firebase编写代码。 Of the functions below, testCreateUserAccount succeeds.在以下函数中,testCreateUserAccount 成功。 testLogin fails with a Type Error at runtime, stating " signInWithEmailAndPassword is not a function " testLogin 在运行时失败并显示类型错误,说明“ signInWithEmailAndPassword 不是函数

From what I have seen in the documentation, createUser is under the same class as signInWithEmailAndPassword , so its not clear to me why attempting to call signInWithEmailAndPassword would fail.从我在文档中看到的, createUsersignInWithEmailAndPassword属于同一类,所以我不清楚为什么尝试调用 signInWithEmailAndPassword 会失败。 Any ideas?有什么想法吗? Thanks!谢谢!

"use strict"; 

var functions = require('firebase-functions');
const admin = require('firebase-admin');

admin.initializeApp(functions.config().firebase);   

exports.testCreateUserAccount = functions.https.onRequest ((req, res) => {
    var email = "joe@example.com";
    var password = "joejoe";

    admin.auth().createUser({
      email: email,
      password: password,
      disabled: false
    });
} );


exports.testLogin = functions.https.onRequest ((req, res) => {
    var email = "joe@example.com";
    var password = "joejoe";

    admin.auth().signInWithEmailAndPassword(email, password);
} );

您在服务器端使用了admin.auth().signInWithEmailAndPassword(email, password) ,您必须在客户端使用它。

Now you could use the identitytoolkit's rest endpoint:现在您可以使用 identitytoolkit 的 rest 端点:

https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=[API_KEY] https://identitytoolkit.googleapis.com/v1/accounts:signUp?key=[API_KEY]

Here you have the documentation:这里有文档:

https://firebase.google.com/docs/reference/rest/auth/ https://firebase.google.com/docs/reference/rest/auth/

You can use Identity toolkit REST API like this then response with idToken.您可以像这样使用身份工具包 REST API,然后使用 idToken 进行响应。 IdToken can be use to verify an account using admin.auth().verifyIdToken(idToken) in Cloud Function. IdToken 可用于使用 Cloud Function 中的admin.auth().verifyIdToken(idToken)验证帐户。

https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=YOUR_PROJECT_API_KEY_THAT_ALLOWS_IDENTITY_TOOLKIT_SERVICE&email=test@gmail.com&password=samplepass&returnSecureToken=true https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword?key=YOUR_PROJECT_API_KEY_THAT_ALLOWS_IDENTITY_TOOLKIT_SERVICE&email=test@gmail.com&password=samplepass&returnSecureToken=true

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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