-1

Getting this issue cancelling Facebook/Google login dialog. The login functionality works perfectly.

My code:

return this.facebook.login(['email', 'public_profile'])
.then(res => {
})
.catch((error) => {
  // can't catch the error
  console.log('error: ', error); // not displayed!
});

This only happens on mobile (Cordova). On the website works properly using Firebase ("User cancelled..."). Working code (desktop):

return this.AngularFireAuth.auth
        .signInWithPopup(new firebase.auth.FacebookAuthProvider())
        .then(function (res) {
        })
        .catch(function (error) {
           // if I cancel the dialog I get the error in this case
        });
Dani
  • 3,128
  • 2
  • 43
  • 91
  • How does the first code block connect with the second code block? (Or does it?) Fundamentally, in the first code block, whatever it is you're returning the promise to needs to handle rejections, and apparently isn't. So *that's* the code to look at, not the code above (unless the second block is that code; if so, tell us how they link up). – T.J. Crowder Feb 18 '18 at 18:31
  • Both functions are not connected eachother. One is for mobile (Cordova) and the other one for desktop. I check this with this.platform.is('cordova') – Dani Feb 18 '18 at 18:57
  • I simplified the login function. I also have .catch() to handle errors but I get the main error before (the catch doesn't work at all here) – Dani Feb 18 '18 at 19:01
  • So...show that. Because if there were a `catch` on the login in the first code block, you wouldn't get the listed error from that code. – T.J. Crowder Feb 19 '18 at 07:41
  • I updated the question with the catch(). As commented I had that code and can't catch the error, so doesn't work – Dani Feb 19 '18 at 09:31
  • The code as shown will definitely catch the error. The problem is in code you haven't shown, probably the "more code" part: At a guess, "more code" involves creating a promise you don't return out of that `then` handler, and don't catch errors from. Alternately, it's coming from code completely unrelated to what's in the question. – T.J. Crowder Feb 19 '18 at 09:40
  • Updated again. The only thing I do is remove the loading spinner – Dani Feb 19 '18 at 09:53
  • Assuming that doesn't involve creating a promise that rejects (which seems a safe assumption!) then the rejection is coming from code unrelated to that block. Your `catch` will **definitely** handle rejections from `login`. – T.J. Crowder Feb 19 '18 at 09:54
  • I wouldn't create this question if so :( – Dani Feb 19 '18 at 10:01
  • All due respect, but I'm afraid that mindset won't help you solve the problem.. [`select` is not broken](https://pragprog.com/the-pragmatic-programmer/extracts/tips). It's not like `.catch` magically doesn't work for you when it works in millions of other bits of code. So clearly, something is going on outside of what you've shown. You need to find that, and you're not going to find it if you insist on saying the problem is in code it clearly isn't in. Good luck! Sounds like no fun. :-) – T.J. Crowder Feb 19 '18 at 11:46

1 Answers1

0

Working code:

return this.facebook.login(['email', 'public_profile'])
            .then(res => {
              const facebookCredential = firebase.auth.FacebookAuthProvider.credential(res.authResponse.accessToken);
              return firebase.auth().signInWithCredential(facebookCredential)
                .then(success => {
                }).catch((error) => {
                });
            }).catch((error) => {
            });
Dani
  • 3,128
  • 2
  • 43
  • 91