I'm in the process of creating a user management page and have set up a callable function on Firebase to handle the creation of new users. The HTML function I've designed is supposed to update existing users or create new ones. However, when testing the functionality by saving a new user, an error occurs despite all variables appearing to match up. Unfortunately, the error message isn't very descriptive, making it difficult for me to pinpoint the issue. Can anyone provide assistance?
This code snippet can be found in 'userManagement.html':
function save(){
if(document.getElementById("password").value === document.getElementById("p2").value){
if(document.getElementById("username").value === ""){
const createUser = firebase.functions().httpsCallable("createUser");
createUser({ email: document.getElementById("email").value, name: document.getElementById("first").value + ' ' + document.getElementById("last").value, phone: document.getElementById("phone").value, password: document.getElementById("password").value})
.then((result) => {
// Read result of the Cloud Function.
console.log(result.data)
});
}
else{
const updateUser = firebase.functions().httpsCallable('updateUser');
// Passing params to data object in Cloud functinon
updateUser({ email: document.getElementById("email").value, name: document.getElementById("first").value + ' ' + document.getElementById("last").value, phone: document.getElementById("phone").value, uid: document.getElementById("username").value})
.then((result) => {
// Read result of the Cloud Function.
console.log(result.data)
});
if(!(document.getElementById("password").value === "")){
const updatePassword = firebase.functions().httpsCallable('updatePassword');
// Passing params to data object in Cloud functinon
updatePassword({password: document.getElementById("password").value, uid: document.getElementById("username").value})
.then((result) => {
// Read result of the Cloud Function.
console.log(result.data)
});
}
}
}
else{
alert("password and confirm do not match")
}
}
The above logic is further implemented in 'index.js' file:
export const createUser = functions.https.onCall(async (data, context) => {
const {email, name, phone, password} = data;
await admin
.auth()
.createUser({
email: email,
displayName: name,
phoneNumber: phone,
password: password,
emailVerified: true,
disabled: false,
}).then((result) => {
// Read result of the Cloud Function.
console.log(result.data)
}).catch(console.error);
return {data: `User updated`}
});
The required imports are as follows:
<script src="/__/firebase/8.7.1/firebase-app.js"></script>
<script src="/__/firebase/8.7.1/firebase-analytics.js"></script>
<script src="/__/firebase/8.7.1/firebase-auth.js"></script>
<script src="/__/firebase/8.7.1/firebase-functions.js"></script>
<script src="/__/firebase/8.7.1/firebase-firestore.js"></script>
<script src="/__/firebase/init.js?useEmulator=true"></script>
Additionally, relevant imports are specified like so:
import * as functions from "firebase-functions";
import * as admin from "firebase-admin";
At present, there are certain errors being encountered: