-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
Hi, I have a problem with the connection authorization after you connect the easygraphql-format-error.
The problem is that, I give information about authorization in req due to the fact that I connected the plugin in context, it stopped being defined.
isAuth.js:
const jwt = require("jsonwebtoken");
module.exports = (req, res, next) => {
const authHeader = req.get("Authorization");
if (!authHeader) {
req.isAuth = false;
return next();
}
const token = authHeader.split(" ")[1];
if (!token || token === "") {
req.isAuth = false;
return next();
}
let decodedToken;
try {
decodedToken = jwt.verify(token, "somesupersecretkey");
} catch (err) {
req.isAuth = false;
return next();
}
if (!decodedToken) {
req.isAuth = false;
return next();
}
req.isAuth = true;
req.userId = decodedToken.userId;
next();
};
app.js:
app.use(isAuth);
app.use("/", (req, res) => {
console.log("req", req),
graphqlHttp({
schema: schema,
rootValue: graphQlResolvers,
graphiql: true,
context: { errorName },
formatError: err => {
return formatError.getError(err);
}
})(req, res);
});
Metadata
Metadata
Assignees
Labels
No labels