24
server/middleware/withUserGraphQLClientMiddleware.js
Normal file
24
server/middleware/withUserGraphQLClientMiddleware.js
Normal file
@@ -0,0 +1,24 @@
|
||||
const {GraphQLClient} = require("graphql-request");
|
||||
|
||||
/**
|
||||
* Middleware to add a GraphQL Client to the request object
|
||||
* Adds the following to the request object:
|
||||
* req.userGraphQLClient - GraphQL Client with user Bearer Token
|
||||
* req.BearerToken - Bearer Token
|
||||
* @param req
|
||||
* @param res
|
||||
* @param next
|
||||
*/
|
||||
const withUserGraphQLClientMiddleware = (req, res, next) => {
|
||||
const BearerToken = req.headers.authorization;
|
||||
req.userGraphQLClient = new GraphQLClient(process.env.GRAPHQL_ENDPOINT, {
|
||||
headers: {
|
||||
Authorization: BearerToken,
|
||||
},
|
||||
});
|
||||
req.BearerToken = BearerToken;
|
||||
|
||||
next();
|
||||
};
|
||||
|
||||
module.exports = withUserGraphQLClientMiddleware;
|
||||
Reference in New Issue
Block a user