express-jwt-authz icon indicating copy to clipboard operation
express-jwt-authz copied to clipboard

Inquiry: Using `jwtAuthz` in a Route Handler function

Open aMahanna opened this issue 3 years ago • 0 comments

Hi! Want to first thank the developers for making express-jwt-authz and express-jwt 🙌

Describe the problem you'd like to have solved

I am trying to use jwtAuthz within a Route Handler function, like such:

var jwt = require('express-jwt');
var jwtAuthz = require('express-jwt-authz');

var options = {};
app.get('/users',
  jwt({ secret: 'shared_secret' }),
  // jwtAuthz([ 'read:users' ], options),
  function(req, res) {
    jwtAuthz([ 'read:users' ], options) // not sure how to make this work here
  }
);

Additional context

I have the following routes:

app.get('/a',
   jwtAuthz(['read:a']),
   ...
);

app.get('/b',
   jwtAuthz(['read:b']),
   ...
);

app.get('/c',
   jwtAuthz(['read:c']),
   ...
);

I want to try the following:

app.get('/:letter',
   function(req, res) {
     jwtAuthz([ `read:${req.params.letter}` ])
   }
);

Hope this makes sense (I am also not sure if this is considered bad practice or not, as I am fairly new to Auth0)

aMahanna avatar Sep 19 '22 23:09 aMahanna