Function call contains an undefined parameter

When working with my Vuex store, I encounter a problem in the action section.

The code snippet in question is as follows:

 actionSignUp({ commit, dispatch }, form) {
  commit("setStatus", "loading")
  auth.createUserWithEmailAndPassword(form.email, form.password)
    .then((response) => {
      console.log(response.user.uid)
      console.log("Successfull registered")
      dispatch("actionCreateUserDocument", form, response.user.uid)
    })
    .catch((error) => {
      commit("setStatus", "failure")
      commit("setError", error.message)
    })
},

actionCreateUserDocument({ dispatch }, form, uid) {
  console.log(uid)
  usersCollection.doc(uid).set({
    email: form.email,
    name: form.name,
    courses: []
  })
    .then(() => {
      console.log("Document successfully written!");
      dispatch("actionFetchUserProfile", uid)
    })
    .catch((error) => {
      console.error("Error writing document: ", error);
    });
},

In the actionSignUp function, when I call console.log(response.user.uid, I get the correct value. However, when I pass the uid to actionCreateUserDocument() using

dispatch("actionCreateUserDocument", form, response.user.uid)
, the uid appears undefined in the actionCreateUserDocument() function.

What could be causing this issue?

Answer №1

The reason for this issue is due to the passing of multiple arguments.

When using Vuex store, you have the option to utilize the following methods:

dispatch(type: string, payload?: any, options?: Object): Promise<any>
dispatch(action: Object, options?: Object): Promise<any>

As a result, the argument response.user.uid is treated as an option by the Vuex Store.

To resolve this, consider refactoring it similar to the following example:

dispatch("actionCreateUserDocument", {
  form,
  userId: response.user.uid
})

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

jQuery event triggers upon completion of execution

A custom code has been integrated into my project using jQuery. Check out the code snippet below: <script> $("#startProgressTimer").click(function() { $("#progressTimer").progressTimer({ timeLimit: $("#restTime").val(), onFinish ...

Can anyone provide a solution for determining the number of active intervals in Javascript?

Similar Question: How to View All Timeouts and Intervals in JavaScript? I've been working on an HTML5 game that includes a lot of graphical effects using intervals created by the setInterval function. However, I've noticed that my game is ru ...

Retrieve the name of the path for the specified * stack within Express.js

When working with Express.js, I am utilizing '*' to catch the error 404. Is there a way for me to find out the path name of the error URL? app.get('*', (req, res) => { console.log("route: " + JSON.stringify(req.route) ...

The Express.io platform is having trouble loading the JavaScript file

Currently, I have an operational Express.io server up and running. However, I am encountering issues with the proper loading of my Javascript files. Here is a snippet from my Jade file: html head h1 Test index body script(src="/so ...

I'm experiencing difficulties with JS on my website. Details are provided below – any suggestions on how to resolve this issue

Can someone help me with a web project issue I'm facing? Everything was going smoothly until I tried to add some JS for dynamic functionality. However, when I attempt to access my elements by tag name, ID, or class, they always return null or undefine ...

How come my effort to evade quotation marks in JSON isn't successful?

When trying to parse a JSON-string using the JQuery.parseJSON function, I encountered an error message that read: Uncaught SyntaxError: Unexpected token R. This was unusual as the only uppercase 'R' in my JSON-formatted string appeared right afte ...

Issue in Vuetify: The value of the first keypress event is consistently an empty string

I need to restrict the user from entering numbers greater than 100. The code snippet below represents a simplified version of my production code. However, I am facing an issue where the first keypress always shows an empty string result. For example, if ...

in node.js, virtual machine scripts can import modules using the require function

I am currently developing a command-line interface using node.js that runs an external script > myapp build "path/to/script.js" myapp is a node.js application that executes the script provided as a command-line argument. In simple terms, it performs ...

Commitment without anticipation of a resolution or rejection

While testing one of my AngularJs Services, I decided to write some Unit tests. Below is a sample code snippet that I have come up with: it('', function(done) { aDocument.retrieveServiceFile(extractedFileFeature) .then(function() { ...

Troubleshoot redirect issues in JavaScript or PHP

I am facing a simple issue that is proving to be time-consuming to solve. The challenge that I am encountering involves an HTML form with 2 buttons. Here is the relevant code snippet: $html1 = "<div class='pai-forms'> <form ...

Testing a Component Function in ReactJS: A Step-by-Step Guide

Testing methods in a Meteor application using mocha/chai can be done like this: describe('postMessage', () => { it('should add message', (done) => { // EXECUTE const messageId = postMessage.call({ articleId: 123, conten ...

When an image is clicked, I am attempting to access data from a Sharepoint list

In my Sharepoint list, there are three columns: Image, Title, and Description. I am using ajax to retrieve the items from the list. The images can be successfully retrieved, but my goal is to display the title and description of the clicked image when an ...

Attempting to create a single function that can be utilized with numerous divs that share the same class in jQuery

Currently, I am working on creating a basic jquery gallery viewer. In my code, I have the following structure: <div class="photoset"> <img /> <img /> </div> <div class="photoset"> <img /> <img /> <i ...

I am having trouble with cookies, as I am unable to retrieve them from my localhost server

Currently, I am in the process of developing a user validation system for my application. However, I have encountered an issue with validating a token as it appears that the necessary cookie is not being retrieved from my browser's storage. Strangely, ...

Uncertain about how to transfer data between server and client in Next.js?

I'm currently grappling with understanding the proper method of exchanging data between server-side and client-side components in NextJS 13. To simplify my learning process, I have created a basic scenario. In this setup, I have two functions that pe ...

Creating dynamic fields for an ExtJS chart

Can chart axes be customized using setFields? I looked through the documentation for a method called setFields, but couldn't find one. While I was able to use setTitle on an axes, setting the field proved to be more challenging. I have a variable ca ...

Having trouble getting images to display in Vue markdown?

I am currently utilizing the vue-markdown package for rendering markdown content. The package works fine except for images, which do not display as expected. Interestingly, when using an img element with the correct file path, the image shows up without an ...

Adding HTML and scripts to a page using PHP and JS

Currently, I am utilizing an ajax call to append a MVC partial view containing style sheets and script files to my php page. Unfortunately, it seems that the <script> tags are not being appended. After checking my HTTP request on the network, I can ...

Passing individual state in Vuex as a parameter

Is there a way in Vuex to mutate two distinct states using the same function, without needing to repeat it for each state in the mutations section? Current approach: state: { firstparam:'', secondparam:'' }, mutations: { add ...

Enhancing your Vue.js component props with descriptive hints

I am currently integrating new components into a project and I want to include information about a specific prop, such as hints or acceptable values that can be passed. Is there a way for my component to display this information when users press ctrl+space ...