docs/api/authentication/hook.md
The authenticate hook will use params.authentication of the service method call and run authenticationService.authenticate().
The hook will
params.provider is set) or do nothing if it is an internal call (params.provider is undefined)params with the return value of the authentication strategyFor example, a successful JWT strategy authentication will set:
params.authentication.payload // The decoded payload
params.authentication.strategy === 'jwt' // The strategy name
params.user // or params[entity] if entity is not `null`
In the following hooks and for the service method call. It can be used as a before or around hook.
Check params.authentication against a list of authentication strategy names.
import { authenticate } from '@feathersjs/authentication'
// Authenticate with `jwt` and `api-key` strategy
// using app.service('authentication') as the authentication service
app.service('messages').hooks({
around: {
all: [authenticate('jwt', 'api-key')]
}
})
Check params.authentication against a list of strategies and specific authentication service. Available options are:
service - The path to the authentication servicestrategies - A list of strategy namesimport { authenticate } from '@feathersjs/authentication'
// Authenticate with `jwt` and `api-key` strategy
// using app.service('v1/authentication') as the authentication service
app.service('messages').hooks({
before: {
all: [
authenticate({
service: 'v1/authentication',
strategies: ['jwt', 'api-key']
})
]
}
})