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

Steps to retrieve an ext.js grid using data from a database

I've been struggling to make a basic Ext.js application work, which is supposed to pull data from a database and show it in an Ext.js grid. However, all I keep getting is "Failure:true". If you could help me identify the mistake, that would be great. ...

Issue encountered: Unable to add MongoDB object to database

Recently, I have encountered an issue with a script that looks like this: use first_db; advertisers = db.agencies.find( 'my query which returns things correctly ); close first_db; use second_db; db.advertisers.insert(advertisers); This error mess ...

How to include an href in a button using Pug without disrupting a form

Is there a way to create a button that redirects to my /leaderboard page once my quiz app submits? h1 Play Time 4 Trivia! button Go form(method='POST') ul each val in questions li ...

Access the value of a specific field within an object using ng-options and use it to filter out other

I have created two separate lists. 1) The first list contains the service names. 2) The second list contains the product names assigned to each service name. Each product has a unique ID that matches it with its corresponding service. app.controller( ...

Adjust the value of module.value() within the Protractor

I am currently working on a project with AngularJS and utilizing Protractor for testing. I would like to modify a value set in module.value(). The module code looks like this: 'use strict'; var app = angular.module('myModule'); app. ...

Eliminate viewed alerts by implementing a scrolling feature with the help of Jquery, Javascript, and PHP

My goal is to clear or remove notifications based on user scrolling. The idea is to clear the notification once the user has seen it, specifically in a pop-up window for notifications. I am relatively new to Javascript/jQuery and feeling a bit confused abo ...

How should event listeners be unbound and child elements removed in single page applications?

I've recently delved into the world of memory leaks in JavaScript while working on a large single-page application. After using Chrome's Profiles (Snapshot) function, I noticed an abundance of detached DOM elements indicating a possible memory le ...

Transform the image data retrieved from an external API into the appropriate format for displaying on the webpage

When I make a call to an external API, it returns image data that I want to render on my page. However, the response looks like this when I log it to the console: https://i.stack.imgur.com/GpDhH.png I'm not very familiar with image formats, so I&ap ...

What is the best way to maintain the connection of this keyword to the window object in webpack?

I recently converted my AngularJS application to es6 using webpack and the import/export syntax. Everything is running smoothly, except for the this keyword. Due to webpack wrapping all of my code into iife functions during compilation (modules), the thi ...

When the Jqueryui dialog is closed, it effectively terminates the current JavaScript thread

Hello there, I'm currently facing an issue with closing my jQuery dialog box. The situation involves a comet connection that sends messages to my browser. My goal is to perform certain actions upon receiving a message, close the dialog, and then conti ...

Upgrade Angular from 12 to the latest version 13

I recently attempted to upgrade my Angular project from version 12 to 13 Following the recommendations provided in this link, which outlines the official Angular update process, I made sure to make all the necessary changes. List of dependencies for my p ...

AngularJS JSON Array

I have an array containing multiple objects in JSON, as well as a select element that contains an array. Depending on the selection made in the first array, another select box will be dynamically loaded right below it. HTML Code <div class="list"> ...

JavaScript prototype error: caught TypeError - attempting to call undefined function

I am facing challenges while attempting to create a Factory in AngularJS. I have moved the code from the controller to the factory and made a few adjustments for it to function properly. Here is the error that I am encountering: "El objeto no acepta la p ...

Exploring Parquet Files with Node.js

Looking for a solution to read parquet files using NodeJS. Anyone have any suggestions? I attempted to use node-parquet but found it difficult to install and it struggled with reading numerical data types. I also explored parquetjs, however, it can only ...

When an accordion is clicked, the content is dynamically loaded within the accordion on the page using PHP, jQuery, and AJAX

To optimize the loading speed of my information-filled page connected to two databases using php, javascript, jquery, I'm looking for a way to make the upload process faster. Currently, some data is displayed immediately while other details are hidden ...

Tips on sending JSON string from Controller action to View and utilizing it as a parameter for a JQuery function

$(document).ready(function () { function initializeMap(data) { var map; alert(data); map = new L.Map('map', { zoom: 8, layers: [OSM] }); var array = $.parseJSON(data); alert( ...

Guide to retrieving the data type of a List Column using SharePoint's REST API

I am currently attempting to determine the type of columns in my SharePoint list so that I can accurately populate a form with the appropriate field types. During my research, I stumbled upon this informative article in the documentation which discusses ac ...

Steps for uploading SVG images to firebase storage

I am encountering an issue while attempting to upload an SVG image to firebase storage. The upload process appears to be functioning correctly, however, when I try to access the link, it returns an error indicating that the file is empty as shown in the sc ...

"Enhance Your Website with Custom jQuery Preloaders

Currently, I am facing a challenge while developing a website. Specifically, I am struggling with resolving the issue of a blank page being displayed. The website that I am working on involves functionality where swiping right triggers data insertion into ...

Issue: Encounter StaticInjectorError while working with deployed Angular CLI project

We encountered an issue while attempting to deploy our Angular CLI (v.1.7.1) project on GitHub Pages and Firebase, resulting in the same outcome for both platforms. The ng serve command functions flawlessly on localhost:4200, and everything goes smoothly ...