Skip to content
demo on how to handle authentication in GraphQL
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
README.md
index.js
package.json
yarn.lock

README.md

graphql-auth-demo

Created with CodeSandbox, the article that properly explains this is here

This was created to demonstrate authentication in GraphQL.

  • create a user
  • authenticate the user
  • generate and validate the token

Used

  • apollo-server v2
  • jsonwebtoken
  • bcrypt
  • pick(from lodash)
  • mongoose

Althought this example uses mongoose and MongoDb, you can easily set up any other database.

Mutations

mutation {
  register(email:"olivier@gmail.com", password:"compl8353pass"){
    email
    password
  }
}
mutation {
  login(email:"olivier@gmail.com", password:"compl8353pass")
}

Queries

{
  users {
    email
    password
  }
  loggedInUser {
    email
  }
}

To-do

  • Use a different database (relational)
  • Migrate to typescript
  • Add more examples to show how relationships work in GraphQL
You can’t perform that action at this time.