From 5699bb6ecddfe2991daffc3d8d37e6d3887ee449 Mon Sep 17 00:00:00 2001 From: James Date: Thu, 16 Apr 2020 13:32:47 -0400 Subject: [PATCH] the case of the missing file --- .../middleware/createAuthHeaderFromCookie.js | 14 ++++++++++++++ src/index.js | 2 +- src/mongoose/connect.js | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/express/middleware/createAuthHeaderFromCookie.js b/src/express/middleware/createAuthHeaderFromCookie.js index e69de29bb..d85b212fd 100644 --- a/src/express/middleware/createAuthHeaderFromCookie.js +++ b/src/express/middleware/createAuthHeaderFromCookie.js @@ -0,0 +1,14 @@ +const createAuthHeaderFromCookie = (req, _, next) => { + if (process.env.NODE_ENV !== 'production' || this.config.productionGraphQLPlayground) { + const existingAuthHeader = req.get('Authorization'); + const { token } = req.cookies; + + if (!existingAuthHeader && token) { + req.headers.authorization = `JWT ${token}`; + } + } + + next(); +}; + +module.exports = createAuthHeaderFromCookie; diff --git a/src/index.js b/src/index.js index 1f7ee271e..cc09cab57 100644 --- a/src/index.js +++ b/src/index.js @@ -56,7 +56,7 @@ class Payload { this.config.routes.graphQL, createAuthHeaderFromCookie, passport.authenticate(['jwt', 'anonymous'], { session: false }), - new GraphQL(this.config, this.collections, this.User, this.Upload, this.globals), + new GraphQL(this.config, this.collections, this.User, this.Upload, this.globals).init(), ); this.router.get(this.config.routes.graphQLPlayground, graphQLPlayground({ diff --git a/src/mongoose/connect.js b/src/mongoose/connect.js index 03aa1573a..8ddc26e97 100644 --- a/src/mongoose/connect.js +++ b/src/mongoose/connect.js @@ -11,6 +11,7 @@ const connectMongoose = async (url) => { urlToConnect = await mongod.getUri(); successfulConnectionMessage = 'Connected to in-memory Mongo server successfully!'; } + mongoose.connect(urlToConnect, { useNewUrlParser: true, useUnifiedTopology: true,