Effect CommunityEC
Effect Community15mo ago
7 replies
Anna | DevMiner

Restricting Access to Path Parameter in HttpApi Middleware

With the new HttpApi, what's the easiest way of restricting access to a specific path parameter in a middleware?

i.e.
const app = fastify()
const myAuth = (req, next) => {
  if (req.path.id === "test") throw new Error('nope')
  next()
}
app.get('/users/:id/', myAuth, ({path}) => ({ id: path.id }))
Was this page helpful?