I need help understanding how to remove a user from my admin panel using the Firebase Admin SDK. When attempting to delete a user, I encountered this error:
Uncaught (in promise) ReferenceError: uid is not defined at eval (ManageCustomer.vue?b113:262)
What might I be doing incorrectly in my code?
Below is the code snippet from index.js that resides in functions folder:
const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();
const db = admin.firestore();
exports.AddUserRole = functions.auth.user().onCreate(async (authUser) => {
if (authUser.email) {
const customClaims = {
customer: true,
};
try {
var _ = await admin
.auth()
.setCustomUserClaims(authUser.uid, customClaims);
return db
.collection("roles")
.doc(authUser.uid)
.set({
email: authUser.email,
role: customClaims,
});
} catch (error) {
console.log(error);
}
}
});
exports.deleteUser = functions.https.onCall(async (data, context) => {
if (!context.auth.token.admin) return;
try {
var _ = await admin
.auth()
.deleteUser(uid)
.then(() => {
console.log("Successfully deleted user");
})
.catch((error) => {
console.log("Error deleting user:", error);
});
} catch (error) {
console.log("error deleting user", error);
}
});
Here is some of the client-side code as displayed within the template section: