AngularJS - Issues with Firebase resetPassword not showing updated changes

When incorrect email addresses are entered and the form is submitted, the error message does not display for the user. However, if additional characters are appended to the existing entries, the message appears on the screen. In debugging, the variable $scope.fError is true and $scope.fErrorMessage contains the correct text, but as mentioned before, it is not shown on the screen.

.controller('PasswordCtrl', ['$scope', '$location', 'CommonProp', function ($scope, $location, CommonProp) {
        $scope.forgotpassword = function(e) {
            e.preventDefault();
            var firebaseObj = new Firebase(CommonProp.getFirebaseURL());
            login.loading = true;
            if ($scope.passwordForm.$valid) {
                firebaseObj.resetPassword({
                    email: $scope.user.emailaddress
                }, function(error) {
                    if (error) {
                        $scope.fError = true;
                        if (error.code == "INVALID_USER") {
                            $scope.fErrorMessage = "The specified user account does not exist.";
                        } else {
                            $scope.fErrorMessage = "Error resetting password:";
                        }
                    } else {
                        $scope.fErrorMessage = "Password reset email sent successfully!";
                    }
                });
            }
        };

    var login = {};
    $scope.login = login;

}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.1/jquery.min.js"></script>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link rel="icon" href="http://getbootstrap.com/favicon.ico">

    <title>AngularJS & Firebase Web App</title>
    <script src="https://code.jquery.com/jquery-2.0.1.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0-rc.0/angular-route.min.js"></script>
    <link href="http://getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="http://getbootstrap.com/examples/signin/signin.css" rel="stylesheet">

    <link href="https://getbootstrap.com/examples/justified-nav/justified-nav.css" rel="stylesheet">
    <script src="https://cdn.firebase.com/js/client/2.0.4/firebase.js"></script>
    <script src="https://cdn.firebase.com/libs/angularfire/1.1.3/angularfire.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
     <script src="forgotpassword/forgotpassword.js"></script>
</head>

<body ng-controller="PasswordCtrl">

    <div class="container">
        <div class="jumbotron" style="padding-bottom:0">
            <h2>Password reset.</h2>
        </div>
        <form class="form-signin" name="passwordForm">
            <div class="form-group" ng-class="{ 'has-error' : passwordForm.emailaddress.$invalid }">
                <input type="email" name="emailaddress" placeholder="Email Address" class="form-control" ng-model="user.emailaddress">
                <p ng-show="passwordForm.emailaddress.$invalid">Enter a valid email.</p>
                <p style="color: red;" ng-show="fError">{{fErrorMessage}}</p>
            </div>
            <button type="button" ladda-loading="login.loading" data-style="expand-right" ng-click="forgotpassword($event);" ng-disabled="!user.emailaddress" class="btn btn-lg segoe-ui-light ladda-button btn-primary btn-block"><span class="ladda-label">Reset</span></button>
        </form>

    </div>

</body>
</html>

Answer №1

The password reset process occurs asynchronously on Firebase servers. Once the operation is complete, the callback function is triggered. However, AngularJS may not be aware of any changes made to the $scope at this point. To address this issue, as suggested by @OleksandrPapchenko, you can inform AngularJS of the change by invoking $apply() or by executing it within a $timeout function:

firebaseObj.resetPassword({
    email: $scope.user.emailaddress
}, function(error) {
    $timeout(function() {
        if (error) {            
            $scope.fError = true;
            if (error.code == "INVALID_USER") {
                $scope.fErrorMessage = "The specified user account does not exist.";
            } else {
                $scope.fErrorMessage = "Error resetting password:";
            }
        } else {
            $scope.fErrorMessage = "Password reset email sent successfully!";
        }
    });
});

This ensures that AngularJS acknowledges the modification to the $scope and updates the user interface during the next update cycle.

It is worth mentioning that Firebase offers a dedicated library for AngularJS known as AngularFire, which simplifies this process for developers. Consider integrating AngularFire for efficient handling of such functionalities.

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

Consolidating multiple inputs into a single saved value

How can I combine three input values into one input field using onchange event in JavaScript? <script type="text/javascript"> function updateInput($i){ $('updateval').val($i); } </script> <input type="text" onchange="updat ...

The Javascript navigation bar is not displaying properly on mobile devices as it should

After customizing the responsive navbar tutorial from W3Schools using CSS and JS, I encountered an issue. I wanted to include a logo and a web page title before the navbar, which worked perfectly when the webpage was maximized. However, when I resized the ...

Retrieve information from a MySQL database and integrate it into a different application

This php script is used to generate a table with a "book" button next to each row. The goal is to extract the values of "phase" and "site" from the specific row where the "book" button is clicked, and transfer them to another form (in "restricted.php") fo ...

Is there a way to prevent tags from wrapping and showcase them all in a single line when utilizing the jQuery select2 plugin?

I have a requirement to prevent tags from wrapping and instead display them in a single line using the jQuery TagIt plugin. Check out my preview: https://i.stack.imgur.com/lYhsi.png My goal is to have all the tags displayed on a single line without wra ...

Discovering unutilized node modules in your React project - A practical guide

Looking for a way to clean up unnecessary node modules and their dependencies from a project. I've done some research online and came across a few NPM packages that claim to achieve this, but none seem to meet my specific needs. Important: Node modu ...

Dynamically retrieving markers from the database based on the most recent timestamp of the last loaded batch

I currently have a database where I store marker locations along with their latitude, longitude, type, and timestamp. Right now, my code loads all markers from the database and displays them on the map with different icons based on their type. However, w ...

Tooltip remains visible even after formatting in highcharts

I have successfully hidden the datalabels with 0 values by formatting them. However, after formatting the tooltips for 0 valued data in a pie chart, there is an issue where hovering over the 0 valued portion shows a white box as shown in the picture. I hav ...

Application experiencing unresponsiveness and encountering a user authorization issue

I am facing two issues: Upon clicking the register button, the application becomes unresponsive and fails to save data to the database. After selecting a photo using the select button, I encounter a user permission error when trying to upload using the u ...

The Javascript countdown feature may experience issues on Safari and IE browsers

Why does this function work in Chrome, but not on IE or Safari? function countdown(){ var dDay = new Date().getUTCDate() + 1; var dMonth = new Date().getUTCMonth() + 1; var dYear = new Date().getUTCFullYear(); var BigDay = new Date(dYear+ ...

Error thrown due to uncaught type mismatch in jQuery AJAX request

I am currently working on transferring Rails-generated json data into Google Maps markers on a map. However, I am still in the learning process of jQuery/JavaScript and trying to grasp the concepts. Unfortunately, I encountered a confusing error message i ...

How to retrieve data obtained from parsing readline and fs in node.js beyond the scope of the callback function

This specific question diverges from the one mentioned with an existing answer. It pertains to a snippet of code taken from node.js documentation involving the use of fs and readfile, with a focus on detecting an end-of-file flag, which appears to be the r ...

Traverse an array containing nested objects using Javascript

I am facing difficulty printing out objects stored in an array. When I console log, this is the result: console.log(product.categories) https://i.stack.imgur.com/YVprQ.png How can I iterate through these nested objects to display them individually like t ...

Issue with Datepicker validation in Angular 5 and Angular Material

I have implemented the most recent version of Angular and Angular Material. I am facing an issue with a datepicker where the validation requirements are not being met as expected. The documentation states that the required attribute should work by default, ...

Collaborate on Typescript Interfaces within a Firebase development environment

I've been developing a Firebase project using Angular for the frontend, and incorporating the @angular/fire library. Within this project, I have created multiple interfaces that utilize firebase and firestore types. For example: export interface ...

What is the best way to ensure an observable has finished before retrieving a value?

Looking at the function provided below: public getAssemblyTree(id: number) { .... const request = from(fetch(targetUrl.toString(), { headers: { 'responseType': 'json' }, method: 'GET' })); request.sub ...

Unexpected behavior with VueJS Select2 directive not triggering @change event

Recently, I implemented the Select2 directive for VueJS 1.0.15 by following the example provided on their official page. However, I am facing an issue where I am unable to capture the @change event. Here is the HTML code snippet: <select v-select="ite ...

Delay the execution of @mouseover in Vue: a guide to managing scope

Looking to implement an action only when the user has hovered over a div for at least 1 second. Here's how it's set up: <div @mouseover="trigger"></div> In the script section: data() { return { hovered: false } } m ...

What is the proper way to structure the DATETIME format when making an API request to mySQL?

Frontend code: import React, { Component, useState, useEffect } from "react"; import Navbar from "../Navbar/Navbar.js"; import BarChart from "../BarChart/BarChart"; ... Backend code: //set up express server const express = require("express"); const app ...

Storing Reusable Field Settings in PHP Object Array

Trying to save a dynamically generated set of fields to the database via $_POST is proving to be a challenge. I'm struggling to convert the options into objects for each fieldset rather than storing them as arrays of options directly. It's a bit ...

I noticed that when using Next.js with the `revalidate: 1` option on a static page, it is triggering two full F5 refresh actions instead of just one. I was hoping for

Currently, I have set up a blog post edit page in my Next.js project. The post pages are utilizing the Incremental Static Regeneration feature with a revalidation time of 1 second for testing purposes. In the future, I plan to increase this to a revalidat ...