'JWT How to bypass certain API routes and http methods
I can make get JSON-Web-Token to ignore paths using .unless like this.
app.use(expressJWT({secret: config.JWTSECRET}).unless({path:
['/register',
'/authentication',
]}));
I have a route with different HTTP methods (get, put, post, delete). I want the GET version of /events to not require a token, but the POST version of /event to require a token. Can I do this without having different routes for GET and POST etc.
/events //GET - no token required
/events //POST - token required
Solution 1:[1]
jwt({ secret, algorithms: ['HS256'] }).unless({
path: [
{ url: /api/products, methods: ['GET', 'OPTIONS'] },
{ url: /api/categories/, methods: ['POST', 'OPTIONS'] },
]
})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Zafar Ijaz Khan Niazi |
