Skip to content

Commit b285e8f

Browse files
committed
Fix support for Apollo Server 2.0
1 parent 16f8097 commit b285e8f

File tree

1 file changed

+4
-2
lines changed
  • packages/graphql-authentication/src

1 file changed

+4
-2
lines changed

packages/graphql-authentication/src/utils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ import { ID } from './Adapter';
44

55
export interface Context {
66
graphqlAuthentication: IGraphqlAuthenticationConfig;
7-
request: any;
7+
request?: any;
8+
req?: any;
89
}
910

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

0 commit comments

Comments
 (0)