GraphQL Cookbook

Logging out a logged user through the Parse GraphQL API

Problem

You want to log out a logged user in your backend through the Parse GraphQL API.

Solution

Using the Parse GraphQL API, you can log out a logged user just by sending the user’s sessionToken through the X-Parse-Session-Token header (as described in the authenticating a user recipe) and calling the logOut mutation. Parse Server will destroy the sessionToken and it will not be accepted for any other future request.

Version Information

Depending on the version of Parse you choose to run, the GraphQL queries, mutations and results will be slightly different. Please choose the correct example along with the Parse version you are running.

Example Parse 3.7.2:
1
2
3
4
5
mutation LogOut {
  users {
    logOut
  }
}
Result Parse 3.7.2:
1
2
3
4
5
6
7
{
  "data": {
    "users": {
      "logOut": true
    }
  }
}
Example Parse 3.8:
1
2
3
4
5
mutation{
  logOut{
    objectId
  }
}
Result Parse 3.8:
1
2
3
4
5
6
7
{
  "data": {
    "logOut": {
      "objectId": "KTznKVzto2"
    }
  }
}
Example Parse 3.9:
1
2
3
4
5
mutation{
  logOut{
    id
  }
}
Result Parse 3.9:
1
2
3
4
5
6
7
{
  "data": {
    "logOut": {
      "id": "Gx2zW7yEnY"
    }
  }
}
Example Parse 3.10:

With Parse 3.10 you must set a header called X-Parse-Session-Token containing the Session Token for the authenticated user. Once it is set, you can call:

1
2
3
4
5
6
7
8
9
mutation{
  logOut(input: { clientMutationId: "sampleId"}){
    viewer{
      user{
        id
      }
    }
  }
}
Result Parse 3.10:
1
2
3
4
5
6
7
8
9
10
11
{
  "data": {
    "logOut": {
      "viewer": {
        "user": {
          "id": "X1VzZXI6UHNOUkJ3Y1YyRQ=="
        }
      }
    }
  }
}