简体   繁体   中英

How to create a firebase cloud function to reset a users password

I am working on an app, and part of the functionality of the app is having an admin login and be able to reset a user's password.

var functions = require('firebase-functions');
var admin = require("firebase-admin");
var serviceAccount = require("/removed-for-privacy.json");
admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: "https://troop-30-elections-web-app.firebaseio.com"
});
    exports.resetPassword = functions.https.onCall((docId,newPass) => {
        console.log("step 2");
        admin.auth().updateUser(docId, {
            password: newPass,
        }).then(() => {
            const modal = document.querySelector('#modal-reset');
              M.Modal.getInstance(modal).close();
              resetForm.reset();
        });
    });

.

 resetForm.addEventListener('submit', (e) => {
            console.log("Step 1");
            e.preventDefault();
            let newPass = resetForm['reset-password'].value;
            const resetPasswordFunction = firebase.functions().httpsCallable('resetPassword');
            resetPasswordFunction(docId,newPass);
            console.log("Step 1.5");
        });

I tried submitting the reset password form, but nothing happened. I looked in the console. There was no error, but I did see step 1 and step 1.5.

Cloud Functions code runs on backend servers and can't access the DOM of the web page that invokes it. This means you can't do things like document.querySelector . If the function requires information to run, you must pass that information from the client app as a parameter to the function.

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