0

I created a test app on facebook and set the domain and the site url to localhost and http://localhost:4200 respectively.

The app is in development mode, as the documentation says "You will still be able to use HTTP with “localhost” addresses, but only while your app is still in development mode", nevertheless I get the error "The method FB.login will soon stop working when called from http pages. Please update your site to use https for Facebook Login." when I invoke the FB.login() api.

Sometimes the facebook window to log the user is not displayed , other times the window opens with the error "Login Error: There is an error in logging you into this application. Please try again later." within.

Update

I'm over https in locale and the relative error is disappeared. This is the function invoked by the "Login with Facebook" button

loginWithFacebook() {
    this.btnLoaderFB = true;
    this.auth.facebookInitializer()
      .then(() => {
        this.auth.facebookInitialized = true;
        return this.auth.facebookLoginStatus();
      })
      .then((loginStatusResponse) => {
        console.log(loginStatusResponse);
        if (loginStatusResponse.status !== 'connected') {
          return this.auth.facebookLogin();
        } else {
          return this.auth.getFacebookProfileInfo();
        }
      })
      .then((profileInfo) => {
        console.log(profileInfo);
        this.auth.loginWithFacebookRemote(profileInfo)
          .subscribe(
            res => {
              this.btnLoaderFB = false;
            }
          );
      })
      .catch(err => {
        console.log(err);
        this.translate.get('t.validation.error_fb_login').pipe(takeUntil(this.unsubscribe)).subscribe(
          t => {
            this.error = t;
            this.btnLoaderFB = false;
          });
      });

The first time I call this function I receive the response from facebookLoginStatus() logged on the console

enter image description here

I enter the fb credential and I get this error

enter image description here

If I try to click again on the button I receive the same response from facebookLoginStatus() I showed in the first image and the facebook popup window shows the same error message in the previous image. If I reload the page the facebookLoginStatus() response is what I expect for a logged user on facebook and the login process ends without error

enter image description here

berno
  • 161
  • 2
  • 11

1 Answers1

0

I can recommend using https even on localhost, especially because you will have a system for testing that is more similar to the live environment. This solves the Facebook https issue once and for all.

For Node.js, it is very easy with this tool: https://github.com/davewasmer/devcert

For PHP, you may want to take a look at this thread: How do I allow HTTPS for Apache on localhost?

For Angular CLI: Get angular-cli to ng serve over HTTPS

andyrandy
  • 72,880
  • 8
  • 113
  • 130
  • I'm developing an angular 7 application with angular cli there is something similar? – berno May 17 '19 at 12:46
  • btw, you will also get many tutorials with google, if you just search for "angular cli https" – andyrandy May 17 '19 at 12:56
  • I tried with https but still remaining my problem. The first time the facebook login's window doesn't open, from the second time I get the error "Login Error: There is an error in logging you into this application. Please try again later" – berno May 20 '19 at 07:29
  • please add exactly what you have tried in your question, are you sure it´s running on https correctly? – andyrandy May 20 '19 at 08:41
  • Yes the https works correctly in fact the https required error for login is not displayed. Few minutes ago I was able to login but I have to use a workaround to finalize the process. Practically I can't start and finish the process in the same "session", I log into fb via the popup window and I get the error I wrote in previous comment, if I try to log the response of `getLoginStatus()` after the login I see authResponse is null and status is "unknown", if I reload the page and run `getLoginStatus()` I receive the correct answer for a logged user on fb and I'm able to log the user – berno May 20 '19 at 09:44
  • you should add the relevant parts of your code in your question, including some screenshots. make is as easy as possible for us to help you ;) – andyrandy May 20 '19 at 09:48
  • for completeness of information when the user log out I check if was logged via facebook and in that case I call the facebook api to logout the user. I don't know what that means and if it can somehow affect my problem – berno May 20 '19 at 09:49