Reputation: 2476
I have the following piece of code which sets up 4 hooks for my FeathersJS service:
service.before({
all: [
auth.verifyToken(),
auth.populateUser(),
auth.restrictToAuthenticated(),
myCustomHook()
]});
The last hook is invoked so I know my code works right overall.
However, the three auth-hooks does not seem to be called, which is what puzzles me. Any suggestions to why this could happen or how I can debug it will be appreciated.
* More details: *
I'm inside a unittest and all I do is this:
app.service('/blockAddresses').find({})
I would expect a failure coming from the auth.restrictToAuthenticated hook. I see no such failure and therefore I conclude that the auth-hooks are never invoked. Of course, this conclusion might be wrong.
Upvotes: 0
Views: 151
Reputation: 44215
The verifyToken
hook will be skipped if the request did not come through the REST or Socket.io API. It checks for params.provider
being set. In a unit test I usually just pass a test { user }
in params
but if you want to verify a token you can set the provider and token like this:
app.service('/blockAddresses').find({
provider: 'test',
token: 'myinvalidtoken'
})
Upvotes: 3