Skip to content

Latest commit

 

History

History
36 lines (25 loc) · 1.45 KB

File metadata and controls

36 lines (25 loc) · 1.45 KB

authenticate

Authenticate users in your app using phoneNumber and deviceId and receive a token in return.

Authentication flow in app

  1. Your app calls the Graphcool mutation authenticatePhoneUser(phoneNumber: String!, deviceId: String!)
  2. If no user exists yet that corresponds to the passed phoneNumber, or the deviceId does not match, an error will be returned
  3. If a user with the passed phoneNumber exists and the deviceId matches, the mutation returns a valid token for the user
  4. Your app stores the token and uses it in its Authorization header for all further requests to Graphcool

Setup the Authentication Function

  • Create a new Schema Extension Function and paste the schema from schema-extension.graphql and code from authenticate.js.
  • add a PAT to the project called the same as your function. The token can be obtained from the Authentication tab in the project settings.

Test the Code

First, you need to create a new user with the signup function. Then, go to the Graphcool Playground:

graphcool playground

and run this mutation to authenticate as that user:

mutation {
  # replace __PHONE_NUMBER__ and __DEVICE_ID__
  authenticatePhoneUser(phoneNumber: "__PHONE_NUMBER__", deviceId: "__DEVICE_ID__") {
    token
  }
}

If the phoneNumber/deviceId combo are valid you should see that it returns a token. The returned token can be used to authenticate requests to your Graphcool API as that user.