How pass params to the Middleware?
See original GitHub issueCongratulations, it’s a cool framework.
I’m need restrict access to route on role-based. This works for me on express:
app.get('/dashboard', middleware.hasRole(['admin', 'creator', 'editor']), function(req,res){});
I have tried to implement a NestMiddleware, but I can not pass the parameters to it:
builder.use({
middlewares: [ HasRole ],
forRoutes: [{
path: 'dashboard',
method: RequestMethod.ALL,
data: { 'roles': ['admin', 'creator', 'editor'] }
}]
})
Here we can think of implementing guardians directly in the controller, inspired by the canActivate concept of Angular2:
{
path: 'dashboard',
component: dashboardComponent,
canActivate: [ RoleGuard ],
data: { roles: [ 'admin', 'creator', 'editor' ] }
}
Something like so:
@RequestMapping({
path: '/dashboard',
method: RequestMethod.GET,
canActivate: [ HasRole ],
data: { roles: [ 'admin', 'creator', 'editor' ] }
})
@kamilmysliwiec What do you think is better, do you plan to implement something like this for the future?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top Results From Across the Web
How to Pass Parameters with Express Middleware
Hey all, Today we will be talking about how you can pass parameters in the Express middleware. We will be explicitly talking about...
Read more >javascript - Passing variables to the next middleware using ...
The most common pattern for passing variables on to other middleware and endpoint functions is attaching values to the request object req ....
Read more >Passing Parameters To Middleware In ASP.NET Core 2.0
How do you pass parameters to middleware during its setup in ASP.NET Core? Solution. In an empty project add a POCO class to...
Read more >How to pass variables to the next middleware using next() in ...
The following example covers how to pass variables to the next middleware using next() in Express.js. Approach: We cannot directly pass data ...
Read more >Pass parameters to middleware from Controller - Laracasts
Hello I have been searching about this topic and I found some answers but nothing solid, so here we are Im developing a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
So finally:
Since RC.8 -
use()
method is deprecated. Instead ofuse()
method you should useapply()
.Old way (deprecated):
New way:
Using
with()
you can pass whatever you want (objects, arrays etc.) to the middlewareresolve(...args)
method. You only have to separate arguments by comma.Now, your
resolve()
method ofHasRole
middleware should looks like that:Where
roles
is an array of arguments passed bywith()
method (in this example, I used spread operator).This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.