GraphQL Cookbook

Logging in an existing user through the Parse GraphQL API

Problem

You want to log in an existing user in your backend through the Parse GraphQL API.

Solution

Using the Parse GraphQL API, you can log in an existing user just by sending the user’s credentials through the logIn mutation. The username and password arguments are mandatory. The mutation will return back all users’s fields, including the sessionToken.

After logging in an existing user, you can use the authenticating an user recipe to send the sessionToken in the following operations so they will be executed in the behavior of this user. You can also use the logging out recipe to destroy the sessionToken.

Example:
1
2
3
4
5
6
7
8
9
10
11
mutation LogIn {
  users {
    logIn(username: "somefolk", password: "somepassword") {
      objectId,
      createdAt,
      updatedAt,
      username,
      sessionToken
    }
  }
}
Result:
1
2
3
4
5
6
7
8
9
10
11
12
13
{
  "data": {
    "users": {
      "logIn": {
        "objectId": "NyU1lNlhPd",
        "createdAt": "2019-07-29T09:09:58.222Z",
        "updatedAt": "2019-07-29T09:09:58.222Z",
        "username": "somefolk",
        "sessionToken": "r:cbca71d29d7601761b48ed01bbe9638d"
      }
    }
  }
}