ExpressJS receives mysterious object communication from AngularJS controller

Currently, I am working on a project that involves creating a login page for an admin that redirects to a dashboard. The server-side is built using Express.js, while the client-side utilizes AngularJS.

The AngularJS controller below is used to retrieve data from the login form:

// Angular Controller for handling login form data
(function () {
    'use strict';
    angular.module("myAdmin", []).controller('loginCtrl', function($scope, $http){
        $scope.login = function() {
            var userEmail = $scope.user.email;
            var userPassword = $scope.user.password;

            $http.post('/admin/', {useremail: userEmail, userpassword: userPassword});   
        }   
    })
})();

This snippet shows the HTML code for the login page:

<!DOCTYPE html>
<html lang="en" >
  <head>
      <!-- Head content goes here -->
  </head>
  <body ng-app="myAdmin">
      <!-- Body content goes here -->
  </body>
</html>

Furthermore, here is the index.js file that serves as the backend in Express.js:

   const express = require('express');
// Server-side functions and routes go here

app.post('/admin/', (req, res) => {
    // Handling post requests to '/admin/'
});

If you're interested in exploring the full project, you can visit the GitHub repository here.

I'm currently facing issues with identifying the data sent from the Angular controller to the Express.js post rendering function. If anyone has insights into this problem or suggestions on how to resolve it, your help would be greatly appreciated. It seems like the firebase auth() function is not executing properly.

Answer №1

Attempt this:

$http({
  method: 'PUT',
  url: '//dashboard/',
  data: {emailAddress:userEmail, password:userPassword}
}).then(function(response){...});

Answer №2

this section contains the angular controller logic

(function () {
    'usestrict';
"this function initializes the angular module"
    angular.module("myAdmin",[]).controller('loginCtrl', function($scope, $http){
        $scope.login = function() {
            var userEmail = $scope.user.email;
            var userPassword = $scope.user.password;
            var myObject = {useremail:userEmail, userpassword:userPassword}

            $http({
                method: 'POST',
                url   : '/admin/',
                data  : JSON.stringify(myObject)
            });   
        }   
    })
})();

this part deals with expressjs functions

   app.post('/admin/', (req, res)=>{
        console.log("####Success");
        console.log('post login '+req.body.useremail, req.body.userpassword);
        admin.auth().signInWithEmailAndPassword(req.body.useremail, req.body.userpassword)
        .then(function (user) {
            res.render('/admin/home');
            console.log("success login admin".user.uid);
        })
        .catch(function(err){
            res.send("fail");
            console.log("Error while executing firebase.auth() ",err);
        });
    });

after consulting remotely, we have reached the final fixed solution

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

Is there a time limit for processing express requests?

My API runs a child process upon request and returns its final output. The processing can take anywhere from 5 to 30 minutes, which is acceptable. However, Express drops the connection after some time and only logs POST /api/v1/check - - ms - -. This means ...

The popup image on my main project is not functioning correctly, despite working perfectly in my test project

I am working on creating a pop-up image for my internship project. When the user clicks on an image, I want it to display in a larger size with a background and opacity. However, the code I have implemented so far is not functioning properly. Please ignore ...

Discovering the accurate HTTP POST status code communication method between a Node.js express server and a jQuery client

With my Node.js app using Express, I've set up a route for handling POST requests to create database objects. app.post('/', function(req, res) { // Create object in DB res.send(''); res.status(201).end(); }); I know t ...

Encountering an issue when attempting to import a non-source module from a node library while running a Typescript script

I have a script that takes input and utilizes the three.js library to apply geometric transformations to the data. I execute this script using ts-node pipeline.ts. Here is the structure of my project: ├── package-lock.json ├── package.json ├ ...

Using jQuery to slide elements across the page

I've been attempting to incorporate a sliding effect into my website, but I'm running into an issue where the sliding only occurs on the first click and I can't figure out why. Here is the code snippet I've been using: Html : $("#go ...

Tips for adjusting CSS font sizes within a contenteditable element?

I am looking to develop a compact HTML editor using JavaScript that allows me to customize the font-size of selected text with a specific CSS value. The documentation states that the FontSize command is used like this: document.execCommand("FontSize", fal ...

Why is Vue JS throwing an error stating "undefined is not an object"?

After creating a Vue app on a single page .html file served by django, which consists of multiple components, I decided to transition this project into a full-fledged Vue.js project using the Vue CLI. Initially, I thought it would be a simple task to trans ...

What steps do I need to follow to get this AngularJs Gallery up and running

As I delve into expanding my knowledge in AngularJS, I've encountered some issues while trying to run code on Plunker. Could someone take a look at the code and point out what I might be doing incorrectly? The code snippet is provided below: var a ...

Tips on displaying data in pie chart legend using react-chartjs-2

I am currently using a pie chart from react-Chartjs-2 for my dashboard. The requirement is to display both the label and data in the legend. I have implemented the following component in my application: import React, { Component } from "react"; ...

Kendo Grid: Issue with adding a new row containing a nested object inoperative

I have been populating a Kendo data grid from nested JSON using the method outlined in this link: Everything was working smoothly until I clicked on the "Add new row" button. At that point, a console error message appeared: "Uncaught TypeError: Cannot r ...

the function DELETE is undefined

Currently, this is my setup: controller.js var app = angular.module('app', [ 'angularFileUpload' ]); app.controller('MyCtrl', [ '$scope', '$http', '$timeout', '$upload', ...

The challenges with implementing makeStyles in React Material UI

const useStyles = makeStyles((theme) => ({ toolbarMargin: { ...theme.mixins.toolbar, marginBottom: "3em", }, logo: { height: "7em", }, tabContainer: { marginLeft: "auto", }, tab: { ...theme ...

"Enhancing the Today Button in FullCalendar with Custom Functionality

My issue lies with the implementation of fullCalendar. Specifically, I am utilizing the week view (defaultView: 'basicWeek') with the toolbar buttons for 'today', 'prev', and 'next'. The problem arises when I click t ...

What could be causing my Fetch GET Request to hang in Node.js?

Having trouble with the getDocuments request in my code. It never seems to complete and stays pending indefinitely. What could be causing this issue? App.js import React, { useState, useEffect } from 'react'; import Grid from './Grid'; ...

I will see the "undefined" entity displayed in the bar chart created using react-chartjs

Using the react-chartjs-2 library, I created a bar chart with the following data: const chartData = { labels: ['Dealer1', 'Dealer2', 'Dealer3', 'Dealer4', 'Dealer5', 'Deal ...

What is the correct way to establish and terminate a MongoDB connection in a Node.js application?

Hey everyone, I have a piece of code at this link (https://github.com/MrRav3n/Angular-Marketplace/blob/master/server.js) and I'm curious if I am properly starting and ending my database connection. Should I connect and end the db connection in every a ...

Getting HTML from Next.js middleware - a step-by-step guide

Is there a way to send the HTTP Status Code 410 (gone) together with a customized HTML message? I want to display the following content: <h1>Error 410</h1> <h2>Permanently deleted or Gone</h2> <p>This page is not foun ...

Exploring the ng-repeat directive's scope

Each item on my list can be highlighted when clicked, using the selectedData class. <div>Remove highlight </div> <ul> <li ng-repeat="data in inputData"> <span title="{{data}}" ng-class="selected ? 'selectedData' : ...

Ways to showcase corresponding information for an item contained within an array?

I'm working with a function that is designed to retrieve specific descriptions for objects nested within an array. The purpose of the function (findSettings()) is to take in an array (systemSettings) and a key (tab12) as arguments, then use a switch s ...

Create a custom hook that encapsulates the useQuery function from tRPC and provides accurate TypeScript typings

I have integrated tRPC into a project that already has API calls, and I am looking to create a separate wrapper for the useQuery function. However, I am facing challenges in getting the TypeScript types right for this customization. My Objective This is w ...