Duplicated anonymous users when session expired in Parse platforms

280 Views Asked by At
if let cachedUser = PFUser.current() {
    // proceed to save some objects
} else {
    PFAnonymousUtils.logIn{ (user, error) in
        // proceed to save some objects
        if ((error as NSError).code == 209) {
            // session expired, logout and call PFAnonymousUtils.logIn again later
            PFUser.logOut()
        }
    }
}

For a simple Swift mobile app, we save data on parse backend anonymously. If there is session expiration error (1 year default on Parser server), we will have to do something about it or we wont be able to save anything anymore. We therefore logout and re-login again.

Once we logout and re-login again, this creates a second new User on the backend.

This creates a problem - we no longer have an accurate picture of the number of users on the backend.

What was wrong in the flow above? Is there a way to prevent duplicated anonymous user when handling expired session?

1

There are 1 best solutions below

0
On

It is possible to increase the default session duration in your server configuration.

You can also add the code below to your server configuration...

expireInactiveSessions: false

This thread may provide further useful insights into this issue.