Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/olivierjm/graphql-auth-demo

demo on how to handle authentication in GraphQL
https://github.com/olivierjm/graphql-auth-demo

apollo-server authentication codesandbox graphql graphql-server server

Last synced: 4 months ago
JSON representation

demo on how to handle authentication in GraphQL

Awesome Lists containing this project

README

        

# graphql-auth-demo

Created with CodeSandbox, the article that properly explains this is [here](https://medium.com/developer-circles-lusaka/https-medium-com-olivierjm-auth-graphql-7f92e8120027)

> 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**

```graphql
mutation {
register(email:"[email protected]", password:"compl8353pass"){
email
password
}
}
```

```graphql
mutation {
login(email:"[email protected]", password:"compl8353pass")
}
```

**Queries**

```graphql
{
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