From 5ebb146d23561c1c3e2b7918f625f095c53e330e Mon Sep 17 00:00:00 2001 From: Arnav Gupta Date: Thu, 31 Jan 2019 22:27:35 +0530 Subject: [PATCH] handle no authorization header case --- src/validators/ApiKeyValidators.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/validators/ApiKeyValidators.ts b/src/validators/ApiKeyValidators.ts index c056191..c693347 100644 --- a/src/validators/ApiKeyValidators.ts +++ b/src/validators/ApiKeyValidators.ts @@ -4,7 +4,8 @@ import {ApiKeyAttrs, ApiKeys} from '../db/models' export function checkValidApiKey (req: Request): Promise { return new Promise((resolve, reject) => { - let apiKey = req.header('Authorization').split('Bearer ')[1] + let apiKey = req.header('Authorization') + apiKey = apiKey && apiKey.split('Bearer ')[1] if (!apiKey) { reject(new Error('No API Key in request')) } @@ -42,4 +43,4 @@ export function checkValidApiKey (req: Request): Promise { -} \ No newline at end of file +}