I am trying to use one variable in two middlewares but it says ( is not defined )
example:
//1st middleware
app.use((req, res, next) =>{
contentType = req.headers['content-type'];
if(contentType === 'application/x-www-form-urlencoded'){
next();
}
})
//2nd middleware
app.use({
)
this is just an example so kindly tell me how would I make ( contentType ) as an accessible variable from the 2nd middleware?
Thanks alot
Here you go, mate. basically, the expressJWT() function returns a middleware that takes 3 parameters, req, res, and next which is used to go to the next middleware, so what I did is that I used the parameters with expressJWT.
//1st middleware
app.use((req, res, next) =>{
req.contentType = req.headers['content-type'];
if(req.contentType === 'application/x-www-form-urlencoded'){
next();
}
})
//2nd middleware
app.use((req, res, next) => expressJWT({
secret: jwk.expressJwtSecret({
jwksUri: req.contentType
}),
})(req, res, next))