Logging Out of Backendless When Using Login With Facebook SDK

I have been using the Login with Facebook SDK, which is great. In my app I am using the FBSDKLoginButtonDelegate to do some clean up when the user presses the Facebook Logout button. I wanted to verify that in order to log the user out of Backendless, it is required to call the Backendless logout method after the user presses the Facebook Logout button. For example, something like the code shown below.

FBSDKLoginButtonDelegate Method

func loginButtonDidLogOut(_ loginButton: FBSDKLoginButton!)
{
        backendless?.userService.logout({ (user : Any?) -> () in
            
            print("The user was logged out.")
        }, error: { (fault : Fault?) -> () in
            
            print("There was an error logging the user out \(fault?.message)")
        })
    }

Take care,

Jon

HI Jon

As I know, Yes you need to call backendless?.userService.logout method

Do you have any problems with it?

Regards Vlad

It’s working well. I’ve noticed four scenarios when working with the Backendless and Facebook tokens for login. I hope it helps someone who is working with the SDKs.

Option 1: Backendless Token == true && Facebook Token == true

Option 2: Backendless Token == true && Facebook Token == false

Option 3: Backendless Token == false && Facebook Token == true

Option 4: Backendless Token == false && Facebook Token == false

Below is code I am using to test each case and then logout of either to prepare to log the user back in.

self.backendless?.userService.isValidUserToken( { (result : Any?) -> Void in
            
            let facebookAccessTokenStatus = FBSDKAccessToken.current()
            
            if (result as AnyObject).boolValue == true && facebookAccessTokenStatus != nil
            {
                 // Both tokens are true.
            }
            else if (result as AnyObject).boolValue == true && facebookAccessTokenStatus == nil
            {
                // The Backendless user token is true and the Facebook user token is false.  Log the user out of Backendless to prepare to log them back in with FB.
                self.backendless?.userService.logout({ (user : Any?) -> () in
                    
                    // Handle logout.
                }, error: { (fault : Fault?) -> () in
                    
                    // Handle any errors.
                })
            }
            else if (result as AnyObject).boolValue == false && facebookAccessTokenStatus != nil
            {
                // The Backendless user token is false and the Facebook user token is true.  Log the user out of Facebook and prepare to log the user back with FB.
                let loginManager = FBSDKLoginManager()
                loginManager.logOut()
                
                ...
                })
            }
            else if (result as AnyObject).boolValue == false && facebookAccessTokenStatus == nil
            {
                //  The Backendless and Facebook user tokens are false.  Prepare to log the user in with FB.
            }
        }, error: { (fault : Fault?) -> Void in
            
              // Handle any errors.
        })