Files
payloadcms/src/express/middleware/createAuthHeaderFromCookie.js
2020-04-16 13:32:47 -04:00

15 lines
398 B
JavaScript

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;