Skip to content

Commit

Permalink
Fix support for Apollo Server 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceK33z committed Jul 26, 2018
1 parent 16f8097 commit b285e8f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions packages/graphql-authentication/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import { ID } from './Adapter';

export interface Context {
graphqlAuthentication: IGraphqlAuthenticationConfig;
request: any;
request?: any;
req?: any;
}

function _getUserId(ctx: Context): string {
const Authorization = ctx.request.get('Authorization');
// For Apollo Server 2.0+ it is ctx.req and for GraphQL Yoga ctx.request. Maybe there is a better way...
const Authorization = (ctx.req || ctx.request).get('Authorization');
if (Authorization) {
const token = Authorization.replace('Bearer ', '');
const { userId } = jwt.verify(token, ctx.graphqlAuthentication.secret) as {
Expand Down

0 comments on commit b285e8f

Please sign in to comment.