Skip to content

Improving Invalid Session Handling #307

Closed
@noahsilas

Description

@noahsilas

According to the documentation on Handling Invalid Session Token Error, the appropriate resolution is to attach an error handler to every call out to the Parse server.

Applying this change to an existing aplication is a bit of a chore in terms of finding all of the appropriate places to add the error handler. It also places a burden on developers to remember to include this handler whenever writing new code.

I can think of a couple ways to address this:

  • Always log the user out on INVALID_SESSION_TOKEN

    We build in to the framework a special case for this error that directly invokes Parse.User.logOut. This has the benefit of immediately changing the state of Parse.User.current to reflect the new information, which may be sufficient for some applications to understand the state change. The downside is that this may be a breaking change in the SDK for some applications that aren't expecting it.

  • Allow registration of a global error handling callback

    Imagine initializing the SDK could look something like:

    Parse.initialize(APP_ID);
    Parse.serverErrorHandler(function(err) {
      if (err.code === Parse.Error.INVALID_SESSION_TOKEN) {
        Parse.User.logOut();
      }
    });

    When this handler is present, it could be automatically invoked whenever we receive an error response from the Parse server. This has the downside of being extra configuration, but is extremely flexible in how it could be used. It also doesn't present any possibility of being an API breaking change, as the behavior would remain the same if the global handler is not registered.

How would folks feel about a pull request for either of these strategies? Are there other options to improve this that folks would rather see?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions