The data for my registration is not getting stored in the Firebase database as expected

I'm currently working on a registration app and it's my first time using firebase.

My email address is successfully stored in the authentication section of firebase. However, when I try to connect my app to the database to store additional information, I encounter an error message upon clicking the signup button:

Error: Reference.child failed: First argument was an invalid path = "undefined". Paths must be non-empty strings and can't contain ".", "#", "$", "[", or "]"
    at validatePathString (firebase.js:1)
    at t.child (firebase.js:1)
    at userServices.js:30
    at angular.js:14634
    at m.$eval (angular.js:15878)
    at m.$digest (angular.js:15689)
    at angular.js:15917
    at e (angular.js:5490)
    at angular.js:5762

Below is the snippet of my code that is causing the issue:

angular.module("registrationApp")
           .factory("signupService", ["$rootScope", "$firebaseAuth", signupService]);

function signupService($rootScope, $firebaseAuth) {
    var ref = firebase.database().ref();
    var auth = $firebaseAuth();

    return {
        signup: function (user) {
            auth.$createUserWithEmailAndPassword(
                user.email,
                user.password
            ).then(function (regUser) {
                var userInfo = ref.child("Users")
                    .child(regUser.uid).set({
                        date: firebase.database.ServerValue.TIMESTAMP,
                        regUser: regUser.uid,
                        firstname: user.firstName,
                        email: user.email

                    })//userInfo
                $rootScope.message = "Hi  " + user.firstName + " " + "Thanks for Registering";
            }).catch(function (error) {
                $rootScope.message = error.message;
            })
        }
    }
}`

Answer №1

It may seem like it's too late, but when I encountered a similar issue, I found that changing regUser.uid to regUser.user.uid solved the problem for me. Here is the revised code snippet:

    var userInfo= ref.child('Users')
               .child(regUser.user.uid).set({
                date: firebase.database.ServerValue.TIMESTAMP,
                regUser: regUser.user.uid,
                firstname: user.firstname,
                lastname: user.lastname,
                email: user.email
               })//userInfo

Answer №2

The issue you're encountering lies with the Reference path you're attempting to use for saving. It's important to remove the 'ref' object and instead follow this method for storing it:

firebase.database().ref(`Users/${loggedInUser.uid}`).set({
    date: firebase.database.ServerValue.TIMESTAMP,
    loggedInUser: loggedInUser.uid,
    firstname: user.firstName,
    email: user.email
})

At present, you're attempting to access a child from an empty source, so ensure to construct a correct reference path for the storage location.

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

Having trouble resolving '@auth0/nextjs-auth0' during deployment on Vercel? Check out this error message: "Can't resolve '@auth0/nextjs-auth0' in '/vercel/path0/pages'"

I recently deployed a project on Vercel and have been working on enhancing the layout to achieve a minimum viable product (MVP). As part of this process, I decided to switch my authentication method to @auth0/nextjs-auth0 package for Next.js. After running ...

Validation of user input using jQuery

Trying to ensure that the form inputs are not empty has been a challenge. Despite using jQuery for input validation, it seems that the inputs are not being properly checked. Strangely, the submit button still allows the form to be submitted: <form id=" ...

Error: The function registerUser from require(...) is not defined

I am facing an issue where I am trying to import the registerUser function inside router.post within the same file that houses its exported function (registerUser). However, when attempting to use it outside of this module, I receive the following error: ...

Access Denied: Origin Issue with OAuth2

I am requesting an authorization code from the OAuth2 Server in order to authenticate a user with my Microsoft App. For more information, I consulted this document. This is my attempt to make the call: function httpGet(){ var theUrl = "https://lo ...

Marionette's Take on the Undead: Zombie Perspectives

Error in JS Console: Uncaught ViewDestroyedError: View (cid: "view351") has already been destroyed and cannot be used. backbone.marionette.js?body=1:1715 Code Snippet: initialize: (options) -> HWAs = @model.get('homework_assignments') @ ...

Run a section of code located in a different file

I have defined some global functions in main.js like this: Vue.prototype._isMobile = function () { return $(window).width() < 768 } //Few more similar functions Now, I want to move these functions to a separate file called util.js: return (function ...

Removing various data entries based on timestamp and additional fields in Firebase Firestore

I stumbled upon a similar query before. Being new to coding, I am attempting to remove all documents in the "users" collection that are older than 1 month and not marked as premium. The deletion criteria involve checking if the "user_online" field is at le ...

Creating toggling elements in Vue.js using dynamic v-show based on index and leveraging falsey v-if

What is the most effective way to use v-show for toggling elements based on their index? I have been able to toggle the elements, but when you click on the element that is already open, it does not close. <div v-for="(btn, index) in dataArray"> ...

Detecting characters in jQuery's onKeyPress with case sensitivity

Is there a way to detect characters in a "case-sensitive" manner using the onkeypress event in jQuery? ...

Can an onSnapshot event be set up for an array in order to track changes?

In my system, each user is associated with multiple groups. Each user's group membership is stored as an array within their user document. Additionally, there is a tasks collection where each task contains an array of authorizedGroups that correspond ...

Is it time to refresh the sibling element when it's selected, or is there

I have recently started working with react and TypeScript, and I am facing some challenges. My current task involves modifying the functionality to display subscriptions and transactions on separate pages instead of together on the same page. I want to sh ...

Troubleshooting the malfunctioning array of objects in Angular

I'm facing an issue with two objects. First object usersHotel usersHotel:[ {id:0, linked:false,hotel: {code:1, namehotel:'r1'} }, {id:1,linked:false,hotel: {code:2, namehotel:'n1'} }, {id:2, linked:false ...

The compatibility between Babel 7 and the preset-es2015 is not very reliable

After reading this useful tutorial on implementing server-side rendering with create-react-app, I attempted to execute the following code snippet: require('ignore-styles'); require('babel-register')({ ignore: [/(node_modules)/], ...

Challenges with Vuex and updating arrays using axios

I am currently facing a challenge with VueJS Vuex and Axios: The issue arises when I retrieve an array with Axios and loop through it to populate its children this way: "Rubriques" has many self-relations, so one rubrique can have multiple child rubriques ...

Is there a way to fetch the version of my npm application without pulling in additional package.json details?

I am working on a Single Page Application (SPA) using React and built with Webpack as part of create-react-app. In my application, I display the version number fetched from package.json like this: import npmInfo from 'package.json' ... <div c ...

To enable the description p tag only when the search box text matches the search criteria, otherwise keep the p tag disabled

I need to develop a search feature that includes a search box, a heading, and a paragraph description. Initially, the description should be hidden, but when a user enters text that matches the description, the paragraph tag should become visible. An exampl ...

A unique technique for creating a stunning visual effect with images using

Can anyone help me with this issue: Check out this animated GIF The images in my project are overlapping when scrolling! How can I achieve a similar effect for my images? Is there a tutorial or plugin available for this? Here is the current code sn ...

angularjs-multiselect-dropdown option angularjs

I am using a dropdown-multiselect component that leverages Bootstrap's Dropdown functionality along with AngularJS directives and data binding. I am new to AngularJS. <li id="bedsLists"> <div ng-dropdown-multiselect="" options="b ...

Conceal the results of echoing json_encode

One dilemma I encountered was passing an array from PHP to JavaScript using json_encode and ajax. The only method that seemed available was to use echo json_encode($var) This approach printed out the contents of $var on the page due to the echo statement ...

Exploring cross-browser compatibility with the use of CSS3 and JavaScript

Starting a new project to create a fresh website. It seems like many people are leaning towards CSS3 and AJAX, neglecting browsers without JavaScript support. They resort to workarounds like enabling CSS3 through JavaScript in older browsers. Is this the ...