The Facebook login pop-up is not visible, however, it is still delivering on its promise

I am currently utilizing the Angular Facebook service found at this link. Within my controller, I am attempting to invoke the method $facebook.login() when a button is clicked using ng-click.

Although the promise is returned and the code inside is executed, no login pop-up appears. I have also attempted disabling the Chrome pop-up blocker without success. There are no errors displayed in the console...

Below are snippets of my code:

facebook.html

<div class="container">
    <div class="col-md-4">
        <h3>Please log in</h3>
        <button type="Log In" class="btn btn-default" ng-click="login()">Log In</button>
    </div>

facebook.js

'use strict';

angular.module('ngsocial.facebook', ['ngRoute', 'ngFacebook'])

.config(['$routeProvider', function($routeProvider) {
    $routeProvider.when('/facebook', {
      templateUrl: 'facebook/facebook.html',
      controller: 'facebookCtrl'
    });
  }])
  .config(function($facebookProvider) {
    $facebookProvider.setAppId('1816664965234931');
    $facebookProvider.setPermissions("email", "public_profile", "user_posts", "publish_actions", "user_photos");
  })
  .run(function($rootScope) {
    (function(d, s, id) {
      var js, fjs = d.getElementsByTagName(s)[0];
      if (d.getElementById(id)) {
        return;
      }
      js = d.createElement(s);
      js.id = id;
      js.src = "//connect.facebook.net/en_US/sdk.js";
      fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));


    (function() {
      console.log("I'm loaded");
    }());
  })


.controller('facebookCtrl', ["$scope" , "$facebook" , function($scope,$facebook) {
  $scope.login = function () {
    $facebook.login().then (console.log("Promise has been returned"));
  }
}]);

Answer №1

$facebook.login().then (console.log("promise has returned"));

It's important to note that just because you use .then, it doesn't necessarily mean the promise has been returned. In your code, you are passing the return value of an immediately executed console.log as the callback function to .then. In Promises, passing a non-function as a callback essentially does nothing.

somePromise.then(undefined).then(function(data) {
    console.log(data);
});

In cases like this, the fulfilled value of somePromise will still be logged, as if .then(undefined) wasn't included at all. This is because .then actually takes two arguments: onfulfilled and onrejected.

To handle errors more effectively, you should consider using

.then(function(data) { 
    console.log(data); 
})
.catch(function(err) { 
     console.log('error', err); 
});

This way, you can see the actual results of $facebook.login() and address any potential issues with the login popup not appearing. If you want to check what exactly $facebook.login() returns, you can do so by assigning it to a variable and logging it:

var p = $facebook.login();
console.log('p is', p);
p.then(function(data) { 
    console.log('data is', data); 
})
.catch(function(err) { 
     console.log('error', err); 
});

If p is indeed a Promise, you should see

p is Promise { <state>: "pending" }

In Firefox, other browsers may display something different. If you notice that p is a promise but neither .then nor .catch is called, it indicates that the promise returned by the function never fulfills.

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

Replicate the form to a new one while concealing the elements and then submit it

Initially, I was working with just one form. Now, I find myself in a situation where I need to utilize a different form which contains the same inputs. This is necessary because depending on the action taken upon submission, different processes will be tri ...

Enhance the post data in jqGrid by including an extra parameter when inserting a new row through a modal form

When trying to add a new record with a modal form in jqGrid, I am having trouble adding an additional dynamic parameter to the POST data. I attempted: $('#table').setPostData({group: id}); $('#table').setPostDataItem('group' ...

Component-driven form validation in Angular 2

I'm facing a challenge with implementing model-driven form validation in my custom input component. Specifically, I need to figure out how to pass ngControl to the component. In the plunkr demo provided at http://plnkr.co/edit/QTmxl8ij5Z6E3xKh45hI?p= ...

Experiencing issues where an undefined value is being returned while attempting to pass a selected value

I'm facing a minor issue with my JavaScript code. Below is the form structure I am working with: <form method="get" name="basic" id="basicId" action="/page2"> <select id="activity" name="activity" class="form-control inputbox"> ...

What could be causing my recursive function to skip over certain parts of my JSON data?

UPDATED TO BE MORE CONCISE Hello, I'm looking for assistance with a recursive function that's not returning the expected values from a JSON object. The goal is to retrieve all "Flow" object IDs where the "Type" is either "Standard" or "Block". T ...

Accessing Row Data from a Material Table using a Button Click, Not through Row Selection

My React component features a material table view, shown here: https://i.stack.imgur.com/OUVOD.png Whenever the delete icon is clicked in the table, I want to access the rowdata associated with that particular row. However, all I am able to retrieve is ...

Unable to transfer information to chart.js graph

I've been struggling to pass my data to the graph, but it just won't cooperate. Interestingly, if I manually input numbers like data: [1,2,3] then it works perfectly fine. In my code, you'll notice that I've console.logged both data.we ...

Is it necessary for Vue-EventBus to have its own dedicated function in order to work effectively?

Encountered a bug while transferring data using eventbus. What I attempted to do was pass the data from 'Quoteinput.vue' to 'Quotebar.vue' in order to update the progress bar length based on the data length present in 'Quoteinput.v ...

The duration from when the Ajax request is sent to when the response is received results in

Has anyone experienced strange results when measuring the time between sending and receiving an ajax request? Sometimes I get negative values. Can someone shed light on this peculiar behavior? var before = 0; var after = 0; $.ajax({ url: 'data.ph ...

The CSS selector for attribute ending with a specific value is not functioning as anticipated

I am facing an issue with selecting elements based on classes ending with either x-control-ui or y-control-ui: <div class="x-control-ui">x-control: <output id="x-control-output"></output></div> <input type=&q ...

Step-by-step guide to adding a skew overlay to your video

I am experimenting with creating a skewed overlay on a video playing in the background at full width. Currently, the skew overlay is functioning perfectly. What if I want it to appear in the bottom-right corner instead of the top-left corner? Would I need ...

The module for the class could not be identified during the ng build process when using the --

Encountering an error when running: ng build --prod However, ng build works without any issues. Despite searching for solutions on Stack Overflow, none of them resolved the problem. Error: ng build --prod Cannot determine the module for class X! ...

Creating a factory class in Typescript that incorporates advanced logic

I have come across an issue with my TypeScript class that inherits another one. I am trying to create a factory class that can generate objects of either type based on simple logic, but it seems to be malfunctioning. Here is the basic Customer class: cla ...

Having difficulty in setting items to a relative position in order to align them properly

I am struggling to align two div items next to each other using Bootstrap. This is for a product detail view where I want the image on the left and text on the right. It's a product detail page for an ecommerce site that I'm trying to create. May ...

Define JSON as writeable: 'Error not caught'

I'm facing an issue with a read/write error in my JavaScript code because the JSON file seems to be set as read-only ('Uncaught TypeError: Cannot assign to read only property'). How can I change it to writable? Should I make changes in the J ...

Discord.js: AbortError: The request was cancelled by the user

Recently, while working on my ticket system and the process for logging transcripts, I encountered an unexpected error that caused transcripts to fail sending. This issue never occurred before. The error message displayed was: [Error Handling System] Multi ...

What is the best way to use res.sendFile() to serve a file from a separate directory in an Express.js web application?

I have a situation within the controllers folder: //controler.js exports.serve_sitemap = (req, res) => { res.sendFile("../../sitemap.xml"); // or // res.send(__dirname + "./sitemap.xml") // But both options are not working }; ...

Hovering on the navigation bar items triggers special visual effects

Hey there, I'm currently working on a small website and I've run into a tricky issue. I have a navigation bar with dropdowns that should fade in when hovering over the main word on the navigation bar. I've tried various methods but nothing s ...

Adding information to a table using React

I have a collection of nested data that I would like to display in a table using React. Each method is represented in one row, as illustrated in the image. How can I create a row for each method along with its corresponding page names? const methods = [{ ...

Errors and warnings caught off guard while running json-server with the --watch flag

I'm having some trouble using json-server in the following way: $ json-server --watch db.json Every time I try to run that command, I encounter errors or warnings depending on the version of json-server that is installed: 1.0.0-alpha.1-1.0.0-alpha.1 ...