Encountering an issue while trying to create a user in Firebase

I am currently following a tutorial on Vue.js from Savvy Apps, which utilizes Firebase with Firestore. As the tutorial mentions that Firestore is still in Beta, I anticipate potential changes - and it seems like that might be happening in this case.

While attempting to sign up a new user by filling out the form and clicking 'Sign up', I encountered the following error message:

Error: Function CollectionReference.doc() requires its first argument to be of type string, but it was: undefined

Interestingly, upon checking Firebase, I noticed that the user had indeed been created. So why am I getting this error message? What exactly should the first argument be?

The signup code snippet looks something like this:

  signup() {
    this.performingRequest = true;
    fb.auth.createUserWithEmailAndPassword(this.signupForm.email, this.signupForm.password).then(user => {
      this.$store.commit('setCurrentUser', user);
      // create user obj
      fb.usersCollection.doc(user.uid).set({
        name: this.signupForm.name,
        title: this.signupForm.title
      }).then(() => {
        this.$store.dispatch('fetchUserProfile');
        this.performingRequest = false;
        this.$router.push('/dashboard')
      }).catch(err => {
        console.log(err);
        this.performingRequest = false;
        this.errorMsg = err.message
      })
    }).catch(err => {
      console.log(err);
      this.performingRequest = false;
      this.errorMsg = err.message
    })
  },

Feel free to request additional code if necessary - this is my initial experience testing Vue.js.

Answer №1

createUserWithEmailAndPassword() method will return a Promise that contains a UserCredential. The UserCredential object includes a property called user which represents the firebase.User object.

To correctly retrieve the UID, you must adjust your code accordingly:

  signup() {
    this.performingRequest = true;
    fb.auth.createUserWithEmailAndPassword(this.signupForm.email, this.signupForm.password)
    .then(credential=> {  // MODIFIED
      this.$store.commit('setCurrentUser', credential.user);  // MODIFIED
      // create user object
      fb.usersCollection.doc(credential.user.uid).set({  //MODIFIED
        name: this.signupForm.name,
        title: this.signupForm.title
      }).then(() => {
        this.$store.dispatch('fetchUserProfile');
        this.performingRequest = false;
        this.$router.push('/dashboard')
      }).catch(err => {
        console.log(err);
        this.performingRequest = false;
        this.errorMsg = err.message
      })
    }).catch(err => {
      console.log(err);
      this.performingRequest = false;
      this.errorMsg = err.message
    })
  },

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

There seems to be an issue with Ajax functionality within the Webix framework

Exploring webix for the first time has been quite an interesting journey. I am carefully following the guidance provided in the getting started document to create my own webix program. By placing my code in an HTML page and two JSON files as instructed, he ...

Retrieving information from an Object within a JSON response

After calling my JSON, I receive a specific set of arrays of objects that contain valuable data. I am currently struggling to access this data and display it in a dropdown menu. When I log the response in the console, it appears as shown in this image: htt ...

Add the text received from the Ajax request to an array specifically designed for AmCharts

Hello, I'm new to JavaScript and seeking assistance. My goal is to create a chart with real-time data from my MCU, but I'm unsure about pushing a string into an array. Currently, the Array (chart.dataProvider) in this code remains undefined. var ...

Hovering into Transition Time

My article card has a transition on the top attribute of the info div, which is supposed to be smooth and last for 0.3 seconds. However, the description suddenly appears during this transition. I'm trying to figure out why this is happening and how to ...

I encounter a CORS issue on Heroku, but strangely it only occurs after 20 minutes of deploying. Prior to that time frame, everything functions seamlessly

Today, I encountered a strange issue while hosting my first Node JS backend on Heroku. Everything runs smoothly when I register/login immediately after deploying the backend. However, if I try to register/login after about 15 minutes, I start receiving a C ...

Can the mDNS string received through webRTC be decoded to retrieve a user's IP address?

After doing some thorough research, I came across this insightful response from a different Stack Overflow question. The problem at hand involves retrieving an mDNS string, which looks like this: abcd1234-1e1e-1e1e-1e1e-abcd1a2bc3de.local I have a genuin ...

Populate two b-form-select components with the same object by using the v-model directive in VueJS with BootstrapVue

I am trying to populate multiple select elements with the values from my "objectSelected" object, but for some reason it is not working within the bootstrap-vue form. There are no error messages displayed, it just simply does not load the values. //My sel ...

Transfer data from an HTML form -> call the ajax load() function

My Current HTML Form Situation Currently, I have an HTML form set up with a text input field and a submit button. When the button is clicked, I want the output results to display in only a specific part of the page without refreshing the entire page. Ste ...

Error: Unable to access 'map' property of an undefined variable in NextJS while using getStaticPaths

Currently facing an issue with dynamic routing in my Next.js project. I have a dynamic page [id].js and am trying to fetch data from an API. const res = await fetch(`myAPI`); const resData = await res.json(); const paths = resData.data.map((r) =&g ...

WordPress REST API - Issue with New Category returning undefined, yet still able to be accessed

Currently, I am utilizing the WordPress REST API and have successfully created a new category. However, when making queries to the API, it is returning undefined for that particular category. Upon visiting: /wp-json/wp/v2/categories, category 17 does not ...

How to Conceal the <th> Tag with JavaScript

I attempted to conceal certain table elements using JavaScript. For <td> elements, it works fine: function hide(){ var x=document.getElementsByTagName('td'); for(var i in x){ x[i].style.visibility='hidden'; ...

The addition operation in JavaScript seems to be malfunctioning as it is not adding up my values

After encountering an issue with calculating the number of payments, I discovered that the addition operator was not functioning as expected. Instead of summing up values, it was treating them as strings. For instance, when trying to add 3 and 5, the out ...

My global variable keeps getting caught by the addEventListener function

My script does not use jQuery and has an addEventListener on a button click. The issue is that after the first run, I want to change the value of "sendingurl" to something else. However, even though sendingurl is updated with the new id value, it doesn&apo ...

observing calls made with twilio using javascript

My goal is to track the status of a phone call happening between two people using their phone numbers. Let's say +558512344321 and +558543211234 are currently on a call. As soon as the call begins, I want the browser to display "Call in progress," and ...

The 'exhaustive-deps' warning constantly insists on requiring the complete 'props' object instead of accepting individual 'props' methods as dependencies

This particular issue is regarding the eslint-plugin-react-hooks. While working in CodeSanbox with a React Sandbox, I noticed that I can use individual properties of the props object as dependencies for the useEffect hook: For instance, consider Example ...

Is AngularJS known for its ability to bind variables across different components effortlessly

In the beginning of my Angular controller, I use Promises to download JSON data and then store it in variables: app.controller('mainController', ['$scope', '$http', '$q', function($scope, $http, $q) { var req1 = $ ...

Issues arising from utilizing Twitter Bootstrap 3.1.x, the box-sizing property, and Revolution Slider

I'm currently working on a PyroCMS theme that is built with Twitter Bootstrap 3.1.x and includes Revolution Slider. However, I've encountered an issue where the property box-sizing: border-box; creates an unwanted grey border as shown in the imag ...

Step-by-step guide on permanently assigning a value in Node.js

I recently started working with node js and I am facing an issue where I need to save an id in a global variable that is required in multiple functions. However, every time the server restarts, the variable gets emptied. Is there a way to persist this va ...

Ways to continuously refresh the display in AngularJS

There are 2 div elements below, and I need to display only one of them depending on whether the doStuff() function is triggered in the controller when a specific anchor element is clicked. <div ng-controller='myController'> <div ng- ...

Some suggestions for updating two div elements using only one Ajax response

My website features a signin() button that I want to enhance with ajax functionality. When the button is clicked, I need it to update two divs: one displaying a personalized welcome message, and the other showcasing a statistics table in a different locati ...