ccoenraets / OpenFB

Micro-library that lets you integrate browser and Cordova apps with Facebook with no plugin or SDK dependency.
MIT License
505 stars 231 forks source link

openfb can't reopen login browser after press done button. #102

Open Krailit opened 8 years ago

Krailit commented 8 years ago

_## Line: 140+. Just Fix like this to open login browser again. =.= _

    function loginWindow_exitHandler() {
        console.log('exit and remove listeners');
        // Handle the situation where the user closes the login window manually before completing the login process
        if (loginCallback && !loginProcessed) loginCallback({status: 'user_cancelled'});
        loginWindow.removeEventListener('loadstart', loginWindow_loadStartHandler);
        loginWindow.removeEventListener('loadstop', loginWindow_exitHandler);
        loginWindow.removeEventListener('exit', loginWindow_exitHandler);
        loginWindow.close();
        loginWindow = null;
        console.log('done removing listeners');
    }

    if (options && options.scope) {
        scope = options.scope;
    }

    loginCallback = callback;
    loginProcessed = false;

    startTime = new Date().getTime();
    loginWindow = window.open(loginURL + '?client_id=' + fbAppId + '&redirect_uri=' + redirectURL +
                              '&response_type=token&scope=' + scope, '_blank', 'location=no,clearcache=yes');

    // If the app is running in Cordova, listen to URL changes in the InAppBrowser until we get a URL with an access_token or an error
    if (runningInCordova) {
        loginWindow.addEventListener('loadstart', loginWindow_loadStartHandler);
        loginWindow.removeEventListener('loadstop', loginWindow_exitHandler);
        loginWindow.addEventListener('exit', loginWindow_exitHandler);
    }

edit: fixed some text

volkangurol commented 8 years ago

@Krailit thanks but it only fixes logout-login problem. Clicking directly done button didnt work for me. I tried in my ionic project - 1- click login facebook button 2 - Inapp browser opens, but i just click done button in the bottom without filling login params. 3- login facebook button not works when i try to click again.

screen shot 2016-03-06 at 00 47 12
Krailit commented 8 years ago

Did you try to chage 'loadstop' EventListener callback funtion ?

in anorther project, I must do this. Still don't know why T.T

    function loginWindow_exitHandler() {
        console.log('exit and remove listeners');
        // Handle the situation where the user closes the login window manually before completing the login process
        if (loginCallback && !loginProcessed) loginCallback({status: 'user_cancelled'});
        loginWindow.removeEventListener('loadstart', loginWindow_loadStartHandler);
        loginWindow.removeEventListener('loadstop', loginWindow_loadStartHandler);
        loginWindow.removeEventListener('exit', loginWindow_exitHandler);
        loginWindow = null;
        console.log('done removing listeners');
    }

    if (options && options.scope) {
        scope = options.scope;
    }

    loginCallback = callback;
    loginProcessed = false;

    startTime = new Date().getTime();
    loginWindow = window.open(loginURL + '?client_id=' + fbAppId + '&redirect_uri=' + redirectURL +
                              '&response_type=token&scope=' + scope, '_blank', 'location=no,clearcache=yes');

    // If the app is running in Cordova, listen to URL changes in the InAppBrowser until we get a URL with an access_token or an error
    if (runningInCordova) {
        loginWindow.addEventListener('loadstart', loginWindow_loadStartHandler);
        loginWindow.addEventListener('loadstop', loginWindow_loadStartHandler);
        loginWindow.addEventListener('exit', loginWindow_exitHandler);
    }
    // Note: if the app is running in the browser the loginWindow dialog will call back by invoking the
    // oauthCallback() function. See oauthcallback.html for details.
volkangurol commented 8 years ago

Unfortunately no, but i noticed that done button only shows in emulator so actually it wont be any problem.