首页 > 解决方案 > 为什么我的 firebase 云功能会运行多次?

问题描述

我为 Firebase 管理员编写了一个云功能。这是重置用户的密码。它传入用户 UID 和新通行证,但是当我运行该函数时,它不仅重置了该用户的密码,还为每个用户设置了密码。数据库中的每个用户。

下面是调用该函数的代码:

resetForm.addEventListener('submit', (e) => {
        e.preventDefault();
        let newPass = resetForm['reset-password'].value;
        const resetPasswordFunction = firebase.functions().httpsCallable('resetPassword');
        resetPasswordFunction({docId: docId, newPass: newPass}).then(() => {
            const modal = document.querySelector('#modal-reset');
          M.Modal.getInstance(modal).close();
          resetForm.reset();
        });
    });

这是功能:

var functions = require('firebase-functions');
var admin = require("firebase-admin");
var serviceAccount = require("./troop-30-elections-web-app-firebase-adminsdk-obsmr-61cc4bb59e.json");
admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: "https://troop-30-elections-web-app.firebaseio.com"
});

exports.resetPassword = functions.https.onCall((data) => {
  return admin.auth().updateUser(data.docId, { 
    password: data.newPass
   })
  .then(() => {
      return {"text": "User Password Successfully Updated"};  // this is what gets sent back to the app
  });
});

标签: javascriptnode.jsgoogle-cloud-functionsfirebase-admin

解决方案


推荐阅读