Friday, January 2, 2015

ParseUser.logout() doesn't logs user out

Recently working on a android app integrated with Parse and Facebook, i observed the issue that just calling the ParseUser.logout() does not clear the authenticated user token and logs in the user again on clicking on 'Log in as Facebook' even if user have logged out from the Facebook app also.


goggled the solution, but found this is as Design :(


So, still if you like to invalidate the facebook authentication token on ParseUser.logout(), you can do by adding a few lines of code shown below.


#################Code Snippet#####################

// Logout already logged in user from your android app.

ParseUser.logout();


// Check if user is logged in Facebook android app or not. If not clear the token information  explicitly.

 com.facebook.Session facebookSession= com.facebook.Session.getActiveSession();
        if (facebookSession== null) {
            facebookSession= new com.facebook.Session(this);
            com.facebook.Session.setActiveSession(facebookSession);
        }
        facebookSession.closeAndClearTokenInformation();

#################Code Snippet#####################

Now, when you click on 'Log in with Facebook', user will be taken to login screen and there you can then log in to your app as different user :)


No comments:

AWS Certified Solutions Architect Associate - AWS Introduction - Questions

All the Best !!! Show Result !! Try Again !! ×