Skip to content

Commit

Permalink
Adjust apollographql#3455 to account for new content in apollographql…
Browse files Browse the repository at this point in the history
…#3506.

This should hopefully make it more clear what information is available on
the argument to `context`, and how it might need to be adjusted for each
specific integration.
  • Loading branch information
abernix committed Nov 14, 2019
1 parent 34fd9de commit 1945392
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions docs/source/security/authentication.md
Expand Up @@ -22,16 +22,21 @@ const { ApolloServer } = require('apollo-server');
const server = new ApolloServer({
typeDefs,
resolvers,
context: ({ request, req }) => {

let combineReq = request || req

// get the user token from the headers
const token = combineReq.headers.authorization || '';

context: ({ req }) => {
// Note! This example uses the `req` object to access headers,
// but the arguments received by `context` vary by integration.
// This means they will vary for Express, Koa, Lambda, etc.!
//
// To find out the correct arguments for a specific integration,
// see the `context` option in the API reference for `apollo-server`:
// https://www.apollographql.com/docs/apollo-server/api/apollo-server/

// Get the user token from the headers.
const token = req.headers.authorization || '';

// try to retrieve a user with the token
const user = getUser(token);

// add the user to the context
return { user };
},
Expand Down

0 comments on commit 1945392

Please sign in to comment.