Persist login between app launches

Hi,

I was wondering how to persist logins between app launches. It seems that it was working before (ParseUser.current wasn’t always nil on launch) but it seems to always be nil now.

Do you have more details about how its persisted and when its not? (i.e. does stopping the app in xcode destroys that session, etc).

Thanks!

The session token should be cached client side and unless a logout or session token invalidation happens, the user should stay logged in.

@cbaker6 Could this client side mechanism be broken in some fashion in 1.2+? I remember it happening before!

It shouldn’t be. I don’t remember a time of it not persisting a user. The testcases check for persisting the sessionToken in the keychain, so if it would have broke, the testcases should have caught it.

I have the latest version in a couple of apps as well as my students use the latest version in their project apps and they haven’t reported any issues about the login not persisting to me.

What version are you using? Is this for iOS?

One thing could be, can you send how you initialize your client? For Linux or Android you will need to provide your own Key/Value Store as they don’t have a Keychain. so they can’t persist between logins on their own. If you are passing in your own store, data could possibly be saved incorrectly.

The majority of the User tests check to make sure the User/session is persisted to the Keychain (whether it’s through BaseParseUser.current (memory key/value store and keychain) or the keychain directly):

When it persists the only ways I can think when it wouldn’t survive an app relaunch is if:

  1. You delete your apps Keychain on purpose
  2. You call logout
  3. You set User.current = nil

Something is weird in my code base as my POUser.current is set within the login completion callback, but always nil, everywhere else. Actually… let me investigate more :blush:

What’s fishy is my isLoggedIn published bool… .current is accurate. Sorry for pointing the finger at your code, when I print POUser.current in the debugger it’s always nil.

when I print POUser.current in the debugger it’s always nil.

Sometimes the debugger is weird when printing optionals. You can try to force unwrap in the debugger to see if it shows current

1 Like

Very much indeed, it is all working fine within ParseSwift. I wasn’t updating my isLoggedIn after initializing ParseSwift :man_facepalming:t3:

Be sure to update to version 1.3.0 is there was a problem fixed where the objectId for ParseInstallation wasn’t being saved to the Keychain. This can cause issues when logging out and logging back in along with updating the Installation. If you use ParseInstallation, you can also remove the DispatchQueue closures that wraps around it (should be the only thing you have to change). Because of this, version 1.3.0 is the lowest version I recommend to use.

I’ll update. I have no use for ParseInstall at this point but I’ll probably learn its utility along the way :blush:

Each device gets an Installation automatically, so you are using it indirectly if you aren’t using it directly. You won’t see it in your Parse Dashboard until you “save”, but it’s in each devices Keychain when they initialize your app. If you decide to use push notifications, you will start using ParseInstallation directly. You can see more here: REST API Guide | Parse