resource-router-middleware icon indicating copy to clipboard operation
resource-router-middleware copied to clipboard

Authentication

Open BramDecuypere opened this issue 7 years ago • 4 comments

How would you add authentication middleware in this for a specific route? For example only in the put/patch/delete method?

BramDecuypere avatar Apr 26 '17 14:04 BramDecuypere

The route handlers can be arrays, you can include an authorization middleware as the first entry in the array and your handler as the second.

developit avatar Apr 26 '17 15:04 developit

I'm also having this problem, @developit can you give an example how it is being done. Something like this?

app.use('/facets', [handlerForPost, handlerForPut], facetResource())

but this isn't effecient as a handler can be different to other resources. :(

jeescu avatar May 23 '17 08:05 jeescu

+1 for the example

pihomeserver avatar Mar 25 '18 19:03 pihomeserver

This is what I did and it seems to work:

// read(req, res) {...}
read: [
	(req, res, done) => {
		console.log("Hello, I'm a middleware");
		done();
	},
	({ resource }, res) => {
		res.json(resource);
	}
] 

ArmandDu avatar Jul 19 '18 12:07 ArmandDu