Firebase allows users to log in multiple times

Each time I press the login button, a strange behavior occurs:

First login: callback indicates 2 logins

First logout

Second login: callback reports 4 logins

Second logout

Third login: callback now shows 5 consecutive logins

and so on.

This is the code for my login function:

$scope.userLogin = function(user){
        $scope.userLoginEmail = user.email;
        $scope.userLoginPassword = user.password;

        $scope.authUser().login('password', {
            email: $scope.userLoginEmail,
            password: $scope.userLoginPassword
        });
        $scope.loginModalHide();
        user.email = '';
        user.password = '';
    };

I'm puzzled by this issue. Why does it happen? Sometimes, even after clicking logout, the login function is triggered automatically.

Answer №1

After reviewing your AuthCtrl, it appears that you're utilizing FirebaseSimpleLogin without the AngularFire bindings, which may lead to issues with the $digest loop. One advantage of using AngularFire is its compatibility with the $digest loop, eliminating the need for manual scope application or timeouts.

AngularFire offers a $firebaseSimpleLogin binding that triggers events on $rootScope when users log in or out.

app.controller('AuthCtrl', function($scope, $rootScope, $firebaseSimpleLogin) {
  var simpleLogin = $firebaseSimpleLogin(new Firebase('<your-firebase>'));

  $scope.user = {
    email: '',
    password: ''
  };

  $scope.login = function() {
    simpleLogin.$login('password', {
      email: user.email,
      password: user.password
    });
  };

  $rootScope.$on('$firebaseSimpleLogin:login', function(e, user) {
    // Handle post login event
  });

  $rootScope.$on('$firebaseSimpleLogin:logout', function(e, user) {
    // Handle post logout event
  });

});

I typically wrap the $firebaseSimpleLogin binding within a factory. You can explore a demo example on Plunker here:

Plunker Demo

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

The bot on Discord.js is sending an incorrect message when attempting to use the _leave command on the music bot

I have been following the tutorials from Plexi Development's YouTube channel to create a music bot. I have implemented the code, but whenever I try to use the _leave command, my bot refuses to leave the voice channel even though I am in the same chann ...

Is there a way to compare timestamps in PostgreSQL using moment.js and focus only on the date aspect?

I've encountered a small issue that has me stumped - I'm trying to figure out the best solution for it. The problem lies in a table I have, with attributes named "Start" and "End". My objective is to store every row in an array where the "Start" ...

How to Calculate the Time Interval Between Two CORS Requests Using jQuery AJAX

When using jQuery's $.ajax to make a CORS request to a web service, there is typically a pre-flight request followed by the actual POST request. I have observed that when there is a time gap between making two web service calls, both a pre-flight and ...

The error message TS2322 in MUI v5 states that the property 'fullWidth' is not found in the type 'IntrinsicAttributes & { theme: Theme; } & { children?: ReactNode; }'

As a user of MUI v5, I have implemented a straightforward FormControl as seen below. It is important to note that the property fullWidth is supported according to the official documentation. import React, { PropsWithChildren } from 'react' import ...

What is the best way to deactivate multiple inputs using JavaScript?

I ran this code snippet: <body> <input placeholder="test1" class="input"/> <input placeholder="test2" class="input"/> </body> <script> document.querySelector(". ...

The subsequent middleware in express next() is failing to trigger the next middleware within the .catch() block

I'm facing a puzzling issue with my POST route. It's responsible for creating transactions through Stripe using the Node package provided by Stripe. Everything works smoothly until an error occurs, such as when a card has insufficient funds. Whe ...

Tips for styling PHP-generated HTML code

I have a snippet of HTML code that needs to be displayed within a specific <div> tag. The HTML code is as follows: <form id="web_formsGenerateFormForm" method="post" accept-charset="utf-8"> <input type="hidden" name="_method" value="POST"/& ...

Sending a sound recording to the express js server with the help of multer

I'm currently working on a project where I need to record audio and save it in my local directory (uploads folder) using express js and multer. The recording part is working fine with mic-recorder-to-mp3, but I'm facing an issue with saving the r ...

What is preventing window.scrollTo() from being executed?

I have implemented Bootstrap's Buttons plugin to toggle the state of a custom checkbox. When the button is toggled on, a hidden element should appear at the top of the page and then the page should scroll to the top. Similarly, when the button is togg ...

Angular filter function encounters an issue if the value being filtered is null

Currently facing an issue while filtering an array. Whenever the filtered field is null, it triggers an error causing the rest of the code to fail. This is how my code looks like: this.order= result.headerText.find((item) => item.textType === 'Orde ...

Configuration of HTTP JSONP variable in Angular

I have successfully implemented http.jsonp for making cross-domain calls. Here is the configuration object I am using: var config = { params: { action: "query", prop: "revisions", format: "json" ...

What is the best method for retrieving data from a specific collection in MongoDB?

Within the code snippet below, on the 4th line, 'Messages' is the name of my MongoDB collection that I created in another file. When I attempt to retrieve data from this collection, no errors occur. However, when I specify the name of a differen ...

Question about MongoDB Concurrency - Ensuring Atomicity with FindOne and FindOneAndUpdate operations

Before I proceed with coding, I kindly request your insights on a specific scenario I am trying to address. Despite reviewing numerous MongoDB documents and forums, I still seek clarity on how certain operations would be executed in my unique situation. ...

Utilizing the spread syntax for elimination

I want to remove a key. Check this out console.log(state); When I do, I get {1: {here is next object}}, next const { 1: deletedValue, ...newState } = state; console.log(newState); console.log(state); But then I end up with {1: {here is next object}} ...

How come my dynamic source path doesn't function correctly unless I add an empty string at the end of it?

Recently, I encountered an issue while using Vue.js to dynamically create a source attribute using an object's properties. Here is the code snippet where I faced the problem: <img :src='"../assets/" + project.image.name + "." + project.image. ...

The directive 'templateUrl' points to the route '/'

I'm having an issue with using the templateUrl in a directive to load a partial. Whenever I try to visit the URL for the template, it redirects me back to /. This results in the partial loading the entire page instead of just the requested partial. a ...

the ever-changing dimensions of a PDF document

I'm attempting to display a PDF using an iframe, but I want the height of the viewer to match the document's height, meaning that all 3 pages should be visible without scrolling. How can I achieve this? Here's a simple example I created on ...

JavaScript - Modifying several object properties within an array of objects

I am attempting to update the values of multiple objects within an array of objects. // Using a for..of loop with variable i to access the second array and retrieve values const AntraegeListe = new Array(); for (let i = 0; i < MESRForm.MitarbeiterL ...

Data is successfully being stored in an array in AngularJS, however, it is not appearing in the user interface

Having an issue with displaying updated data on my UI. I am successfully pushing data into the database and an array using Angular 2-way binding. The data is being pushed as confirmed by the console, but it's not showing up on the user interface. Con ...

Mocking a promise rejection in Jest to ensure that the calling function properly handles rejections

How can I effectively test the get function in Jest, specifically by mocking Promise rejection in localForage.getItem to test the catch block? async get<T>(key: string): Promise<T | null> { if (!key) { return Promise.reject(new Error(&apo ...