Sprotte
Sprotte

Reputation: 541

JWT Restify exclude Path and all Subpaths

At the moment i use the Node Module jwtRestify for authentication. And i have one problem, i would like exclude some paths from the authentication which is no problem with:

server.use(jwtRestify({
secret: config.secret,
requestProperty: 'decoded'}).unless({
  path: [
    baseUrl + '/login',
    baseUrl + '/admin/users',
    baseUrl + '/admin/users/:id',
  ]}))

But the /admin/users/:id dont work at all is there a way to exclude all admin routes with something like an regex?

Upvotes: 0

Views: 558

Answers (1)

Sprotte
Sprotte

Reputation: 541

A bit late but i found a solution. Underneath restify is using express unless and you can simply use a regex like in the following:

server.use(jwtRestify({
secret: config.secret,
requestProperty: 'decoded'}).unless({
  path: [
    baseUrl + '/login',
    baseUrl + '/admin/users',
    /^\/api\/v0\/admin\/users\/.*/,
  ]}))

Upvotes: 1

Related Questions