jfromaniello / express-unless

Conditionally add a middleware to express with some common patterns
MIT License
178 stars 27 forks source link

Exclude a route with uuid v4 #29

Closed carlocorradini closed 4 years ago

carlocorradini commented 4 years ago

I need help to exclude from a JWT protected route the path to /api/v1/auth/verify/:uuid where :uuid is a UUID v4. I've tried different regex from StackOverflow but none worked.

Here is my code:

import { Router } from 'express';
import jwt from 'express-jwt';
import config from '@app/config';
import auth from './auth';

const router = Router();

router.use(
  '/auth',
  jwt({
    secret: config.SECURITY.JWT.SECRET,
  }).unless({
    path: [
      {
        url: '/api/v1/auth/verify/:uuid',
        methods: ['POST'],
      }
    ],
  }),
  auth
);

Thanks in advance.

enero-o commented 4 years ago

https://github.com/jfromaniello/express-unless/issues/19#issuecomment-285142465

You would need to use Regex example - { url: /\/v1\/stores\/domain/i, methods: ['GET'] },

I just saw your SO link, instead of trying to identify a UUID string Try and achieve a /api/v1/auth/verify/* with regex

carlocorradini commented 4 years ago

@aiveneh Unfortunately I can't.I have to exclude only that specific endpoint with a Regex for UUID v4. I tried many Regex but none worked. Can you help me:disappointed_relieved:? Thanks:persevere:

enero-o commented 4 years ago

Try this regex

{ url: /\/api\/v1\/auth\/verify/i, methods: ['POST'] }