ios - Parse, how to handle an invalid session? -
straight documentation, says that:
pfuser#currentuser() gets logged in user disk , returns instance of it.
this fine , all, if user logged in @ disk isn't user that's logged in on server. lets users account has been deleted whatever reason, or session no longer valid due database modifications. these problems i'm facing.
throughout tutorials i've read, i've seen using following line of code way check if user valid, , can skip login stage of application:
if let user = pfuser.currentuser() as? subclass { // simulate successful login } however, posing problem me, successful login simulated, login not successful. here error i'm dealing with:
[error]: invalid session token (code: 209, version: 1.12.0)
so first thing did attempt log user out, fails (i assume because user wasn't logged in begin with) , i'm thrown application crashes because data required server isn't there. here's how attempted handle error code 209:
let query = pfquery(classname: "foo") query.wherekey("bar", equalto: "foo") query.findobjectsinbackgroundwithblock { (foo, error) -> void in if let error = error { print(error); if error.code == 209 { pfuser.logoutinbackgroundwithblock { (error) -> void in if let error = error { print("okay, i'm trapped!"); } } } } } the output of "query" following:
[error]: invalid session token (code: 209, version: 1.12.0) okay, i'm trapped! i'm out of ideas on here, , i'm ripping hair out trying figure out how validate user upon application launch. seems redundant have catch error code 209 on every query, if that's have do, that's have do.
you can use synchronous logout. if error occurs, doesn't matter. pfuser session token invalidated if user launches app again.
also latest parse sdk provides pfconstants class, provides enum possible error cases.
kpferrorinvalidsessiontoken = 209.
if (error.code == kpferrorinvalidsessiontoken) { pfuser.logout() //necessary pop of view controllers after executing previous code. }
Comments
Post a Comment