I attempted to create a callable function for creating a user, but I encountered an error when running it and I am unable to determine the cause

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:

https://i.sstatic.net/WdgiD.png

https://i.sstatic.net/anZhE.png

Answer №1

Grateful for the assistance I received after realizing I forgot to initialize admin sdk.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How come I'm encountering issues when trying to click on the "register-selection" button in my Bootstrap and JS setup?

I am facing a challenge while developing my website. I want to trigger an alert when the "register-selection" is clicked, but despite trying both Jquery and vanilla Javascript, I have not been successful. Even after searching online resources and ChatGPT f ...

Why is it necessary to use process.nextTick() to delay method execution within a PassportJs strategy using Express?

When working with user registration using the passport local strategy, I stumbled upon a code snippet that utilizes process.nextTick to postpone the execution of a method within the Passport LocalStrategy callback. While I grasp the concept of delaying m ...

jinja2.exceptions.TemplateSyntaxError: instead of 'static', a ',' was expected

My current project involves using Flask for Python, and I encountered an error when running the project from PyCharm. The error message points to line 192 in my home.html file: jinja2.exceptions.TemplateSyntaxError: expected token ',', got &ap ...

Problems with the firing of the 'deviceready' event listener in the PhoneGap application

Utilizing vs2012, I have been working on a PhoneGap application. Within this application, the following JavaScript code is being used: document.addEventListener("deviceready", onDeviceReady, false); function onDeviceReady() { // alert("hh") ...

What are some ways to customize the appearance of React Semantic components?

Is there a way to apply CSS for react semantic UI when using create react app? I have installed semantic-ui-react and included the CSS CDN: loginForm.js: import React from "react"; import { Button, Form, Header } from "semantic-ui-react"; import styles f ...

Incorporating a Favicon into your NextJs App routing system

Encountering an issue with the new Next.js App Router. The head.js files have been removed, thus according to the documentation I need to implement metadata in layout.ts. My favicon file is named favicon.png. How should I specify it within the following c ...

The onclick attribute on a button in HTML is not functioning properly following the inclusion of an Ajax load

I am facing an issue with a button that is being dynamically loaded from PHP code using Ajax. The button has an onclick attribute that calls a function named viewImage. The Ajax request is triggered every 5 seconds inside the loadImages function. Snippet ...

Storing the DOM in a Variable

I have saved the response of an XMLHttpRequest() into a variable from a specific website, let's say yahoo.com. How can I retrieve the values of the DOM content using either getElementById or getElementsByName on this variable? For instance: var dump ...

Managing Z-index (navigation) in Java Selenium 2.0 by addressing z-index conflicts prior to executing the built-in scroll function followed by the WebElement

When using Selenium 2.0, the .click() method has the capability to automatically scroll until the element is visible and can be clicked on, as shown in the code snippet below: WebElement box = driver.findElement( By.id( boxID ) ); box.click(); Generally, ...

Generate a dynamic jqplot chart using data retrieved from a variable and JSON data

I'm struggling with loading data into a jqplot chart via variables as it only displays the first value. I am puzzled as to why this is happening. JavaScript: $(document).ready(function () { var sin = [[20, 10, 0, 10, 15, 25, 35, 50, 48, ...

Dealing with nested file includes in PHP and passing values to a JavaScript function

When the button is clicked on login.php, it triggers the execution of redirect.php. This redirect.php file carries out Twitter authentication, which includes invoking another file that eventually calls index.php. index.php provides the result in the form ...

Unable to access path for children through buttons in parent path

As a data scientist entering the world of frontend development, I find myself faced with the task of creating a UI at the request of my boss. Please bear with me as I attempt to explain my issue in layman's terms. Currently, I am using Vue.js and hav ...

Why does a Vue component throw errors prior to being rendered?

In the Home view, there are two components: Filter and Results. The Results component relies heavily on data from the vuex store, which is influenced by the Filter component. Once the filters are applied and the user interacts with Filter, the necessary da ...

Express Session Issue Preventing Ajax Call from Functioning

After testing the /temp route directly in the browser and then through an ajax call to the /test route, I noticed a difference in the session information. When accessed directly, the session retains the data added via the /temp route, but when called throu ...

jQuery functions smoothly on Firefox, but encountering issues on Chrome

While it may seem like a repetitive inquiry, I have thoroughly researched similar questions and have not found a suitable solution. The server is returning the following response through a standard ajax call: <form id="ctl00" name="ctl00" method="post ...

JavaScript Await Dynamic User Input

I have implemented a modified version of a script for generating random numbers in multiple columns of a spreadsheet, inspired by Tim Cooper's solution on stackoverflow. This script works by selecting a range of cells and running it from an onOpen men ...

Automatically populate email fields with pre-filled form data

Looking to create an HTML form that utilizes JS/jQuery (no PHP) to capture data from "subject" and "message" fields and send an email. The goal is for the client-side code to open the user's mail client, pre-fill the subject and body with form data, a ...

Encountering an "unexpected token" error while utilizing the JSOP API in a ReactJS application

I am facing an issue while fetching data from a JSON API, as it is throwing an "Unexpected token" error. Below is the code that I have tried so far. Any help in resolving this problem would be greatly appreciated. Below is the code snippet: var Demo = Re ...

What is the process of generating enum values using ES6 in Node.js?

Can JavaScript support enumerations with assigned integer values, similar to how other programming languages handle it? In C#, for instance, I can define an enum as follows: enum WeekDays { Monday = 0, Tuesday =1, Wednesday = 2, Thursday ...

Determine the value of a field by utilizing the values of two other fields through an onChange event

Setting the Stage: Imagine a scenario with 3 key fields: quantity, singlePrice, and totalPrice. I want these fields to be part of my form, with totalPrice being dynamically recalculated whenever quantity or singlePrice changes. My Approach: I created ...