Skip to content

Commit

Permalink
Bring 2.0.0 in line with master (#250)
Browse files Browse the repository at this point in the history
* Update neo-push-server to enforce nodemon uses local ts-node install
(force rerun cla check)

* Fix typos

* refactor: add more debug logs for get jwt

Co-authored-by: Evan Reed <[email protected]>
Co-authored-by: Matt Murphy <[email protected]>
Co-authored-by: Daniel Starns <[email protected]>
  • Loading branch information
4 people authored Jun 15, 2021
1 parent ad665ca commit e207a02
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion examples/neo-push/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "",
"main": "./dist/src/index.js",
"scripts": {
"start": "nodemon --watch './src/**/*.ts' --exec ts-node -r tsconfig-paths/register --project ./src/tsconfig.json ./src/index.ts",
"start": "nodemon --watch './src/**/*.ts' --exec ./node_modules/.bin/ts-node -r tsconfig-paths/register --project ./src/tsconfig.json ./src/index.ts",
"build": "tsc --project src/",
"seed": "ts-node -r tsconfig-paths/register --project ./src/tsconfig.json ./src/seeder.ts",
"test": "jest"
Expand Down
23 changes: 14 additions & 9 deletions packages/graphql/src/auth/get-jwt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,35 @@ function getJWT(context: Context): any {

if (!jwtConfig) {
debug("JWT not configured");

return result;
}

const req = context instanceof IncomingMessage ? context : context.req || context.request;

if (
!req ||
!req.headers ||
(!req.headers.authorization && !req.headers.Authorization) ||
(!req && !req.cookies && !req.cookies.token)
) {
debug("Could not extract request from context");
if (!req) {
debug("Could not get .req or .request from context");

return result;
}

if (!req.headers && !req.cookies) {
debug(".headers or .cookies not found on req");

return result;
}

const authorization = req.headers.authorization || req.headers.Authorization || req.cookies.token;
const authorization = (req.headers.authorization || req.headers.Authorization || req.cookies.token) as string;
if (!authorization) {
debug("Could not extract authorization header from request");
debug("Could not get .authorization, .Authorization or .cookies.token from req");

return result;
}

const token = authorization.split("Bearer ")[1];
if (!token) {
debug("Authorization header was not in expected format 'Bearer <token>'");

return result;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/graphql/src/schema/make-augmented-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@ function makeAugmentedSchema(
interfaces: nodeInterfaces,
otherDirectives,
...nodeFields,
// @ts-ignore we can be sure its defined
// @ts-ignore we can be sure it's defined
auth,
// @ts-ignore we can be sure its defined
// @ts-ignore we can be sure it's defined
exclude,
description: definition.description?.value,
});
Expand Down

0 comments on commit e207a02

Please sign in to comment.