title: Parse, how to handle an invalid session?
body: <p>Straight from the documentation, it says that:</p>
  
  <blockquote>
    <p>PFUser#currentUser() gets the currently logged in user from disk and
    returns an instance of it.</p>
  </blockquote>
  
  <p>This is fine and all, but what if the user logged in @ disk isn't a user that's logged in on the server. Lets say the users account has been deleted for whatever reason, or the session is no longer valid due to database modifications. These are currently the problems that I'm facing.</p>
  
  <p>Throughout the tutorials that I've read, I've seen using the following line of code as a way to check if the user is valid, and thus you can skip the login stage of the application:</p>
  
  <pre><code>if let user = PFUser.currentUser() as? Subclass {
      // Simulate successful login
  }
  </code></pre>
  
  <p>However, this is posing a problem for me, as the successful login is simulated, but the login was not successful. Here is the error I'm dealing with:</p>
  
  <blockquote>
    <p>[Error]: invalid session token (Code: 209, Version: 1.12.0)</p>
  </blockquote>
  
  <p>So the first thing I did was attempt to log the user out, however this fails (I assume because the user wasn't logged in to begin with) and now I'm thrown into application which immediately crashes because the data required by the server isn't there.  Here's how I attempted to handle error code 209:</p>
  
  <pre><code>let query = PFQuery(className: "Foo")
  query.whereKey("Bar", equalTo: "Foo")
  query.findObjectsInBackgroundWithBlock {
      (foo, error) -&gt; Void in
      if let error = error {
          print(error);
          if error.code == 209 {
              PFUser.logOutInBackgroundWithBlock {
                  (error) -&gt; Void in
                  if let error = error {
                      print("Okay, I'm trapped!");
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>The output of this "query" is the following:</p>
  
  <pre><code>[Error]: invalid session token (Code: 209, Version: 1.12.0)
  Okay, I'm trapped!
  </code></pre>
  
  <p>I'm out of ideas over here, and I'm ripping my hair out trying to figure out how to properly validate a user upon application launch. It seems redundant to have to catch error code 209 on every query, but if that's what you have to do, then that's what you have to do.  </p>