Last active
October 5, 2018 17:13
-
-
Save JakeDawkins/9046ec0bc65e92b759cc0b39bff62ef3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| context: ({ req }) => { | |
| // get the user token from the headers | |
| const token = req.headers.authentication || ''; | |
| // try to retrieve a user with the token | |
| const user = getUser(token); | |
| // optionally block the user | |
| // we could also check user roles/permissions here | |
| if (!user) throw new AuthenticationError('you must be logged in to query this schema'); | |
| // add the user to the context | |
| return { | |
| user, | |
| models: { | |
| User: generateUserModel({ user }), | |
| ... | |
| } | |
| }; | |
| }, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment