1

I have an ios application, I have implemented Facebook login through Parse. Everything works great in the first trial.

  • I can login via Facebook
  • My details are stored in the PFUser.currentUser()
  • I am able to pull information from the Graph API

But things start to become a problem when I logout (PFUser.logOut()) , and delete the User row from the Parse class and delete the app from Facebook.

The following methods still show that the user is logged in and authenticated.

if let user = PFUser.currentUser() {
if user.isAuthenticated()

I am guessing it is because current user is still using the cached copy of the User. I try executing

do
{
  try PFUser.currentUser().fetch()
}
catch{
print("User refreshed")
}

But it does not refresh the currentUser() and gives an error. How can I refresh the PFUser.currentUser(), so that it stops saying that the user is logged in and authenticated, even though it's not

Thanks

Parth Tiwari
  • 855
  • 2
  • 9
  • 23

1 Answers1

0

I got an answer here,

Swift & Parse - PFUser currentUser never equals nil

I've been struggling with logging out for a little while and I believe I have finally cracked it!

No matter what I did, when I used "PFUser.logOut()" would never set "PFUser.currentUser()" to nil, but it would set "PFUser.currentUser()!.username" to nil...

Because of this I used

var currentUser = PFUser.currentUser()!.username

as a global variable to track is a user is logged in.

On my login/first page I added

override func viewDidAppear(animated: Bool) {

if currentUser != nil {

    self.performSegueWithIdentifier("login", sender: self)

}

}

and finally on my logout button i used

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

if segue.identifier == "logout" {

    PFUser.logOut() //Log user out

    currentUser = PFUser.currentUser()!.username //Reset currentUser variable to nil

}

}
Community
  • 1
  • 1
Parth Tiwari
  • 855
  • 2
  • 9
  • 23