Skip to content

Instantly share code, notes, and snippets.

@JakeDawkins
Last active May 21, 2018 07:46
Show Gist options
  • Save JakeDawkins/ef1c5abc4d36696449e4f74f356a9264 to your computer and use it in GitHub Desktop.
Save JakeDawkins/ef1c5abc4d36696449e4f74f356a9264 to your computer and use it in GitHub Desktop.
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 AuthorizationError('you must be logged in');
// add the user to the context
return { user };
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment