zyra / ngx-facebook

Angular TypeScript Wrapper for Facebook SDK
http://zyra.github.io/ngx-facebook/
MIT License
209 stars 70 forks source link

FB.login() called when user is already connected. #125

Open ssougnez opened 6 years ago

ssougnez commented 6 years ago

Hello,

when the user tries to login while he already is, the error FB.login() called when user is already connected. appears in the console. I think this could be easily fixed with something like this:

FacebookService.prototype.login = function (options) {
    return new Promise(function (resolve, reject) {
        try {
            FB.getLoginStatus((response) => {
                if (response.status == "connected") {
                    resolve(response);
                }
                else {
                    FB.login(function (loginResponse) {
                        if (loginResponse.authResponse) {
                            resolve(loginResponse);
                        }
                        else {
                            reject();
                        }
                    }, options);
                }
            });
        }
        catch (e) {
            reject(e);
        }
    });
};

I just tested it roughly and it seems to be working fine. Additional tests would be nice though.