Zekep
Zekep

Reputation: 41

PFUser.current() always returns nil

In the viewDidLoad() of the Initial View Controller in my app I run this:

let currentUser = PFUser.current()

        if currentUser != nil{

        self.performSegue(withIdentifier: "toTabs", sender: self)
    }

currentUser is always nil.

I run PFUser.enableAutomaticUser() in the AppDelegate.Swift after I configure the parse client as per the latest parse server Ios SDK. This should make it so that when ever a user is logged in they stay logged in unless a logout command is run. I have no idea why this isn't happening.

Upvotes: 1

Views: 403

Answers (3)

Zekep
Zekep

Reputation: 41

After much debugging, I realized that PFUser.enableAutomaticUser() was functioning normally. The problem was that the self.performSegue(withIdentifier: "toTabs", sender: self) wasn't dispatched to the main queue. I fixed this by changing my code to:

 let currentUser = PFUser.current()

    if currentUser?.username != nil{

        print(currentUser!)

        DispatchQueue.main.async(){

        self.performSegue(withIdentifier: "toTabs", sender: self)

        }

    }else{

        print("No current User")
  }

Thanks, to all of you for your help, and I'm sorry to have wasted your time with this.

Upvotes: 1

Nirmalsinh Rathod
Nirmalsinh Rathod

Reputation: 5186

I enable keychain sharing, clean, delete the app, and reinstall to get things to work properly.

Here are steps to enable keychain.

Upvotes: 0

Enrique
Enrique

Reputation: 303

I had the same problem running Parse version 2.2 (or older, not sure), where did you call the PFUser.enableAutomaticUser()?, I solved it by calling it right after the ApplicationID was made:

Parse.setApplicationId(parseApplicationID, clientKey:parseClientKey)
PFUser.enableAutomaticUser()

Upvotes: 0

Related Questions