David Luecke c606c56dc2
chore: Format code using Prettier and updated ESLint rules (#2647)
Co-authored-by: Marshall Thompson <marshall@creativeideal.net>
2022-05-27 15:21:13 -07:00

59 lines
1.3 KiB
TypeScript

import { feathers } from '@feathersjs/feathers'
import { memory, MemoryService } from '@feathersjs/memory'
import { AuthenticationService, JWTStrategy } from '@feathersjs/authentication'
import { LocalStrategy, hooks } from '../src'
const { hashPassword, protect } = hooks
export type ServiceTypes = {
authentication: AuthenticationService
users: MemoryService
}
export function createApplication(app = feathers<ServiceTypes>()) {
const authentication = new AuthenticationService(app)
app.set('authentication', {
entity: 'user',
service: 'users',
secret: 'supersecret',
authStrategies: ['local', 'jwt'],
parseStrategies: ['jwt'],
local: {
usernameField: 'email',
passwordField: 'password'
}
})
authentication.register('jwt', new JWTStrategy())
authentication.register('local', new LocalStrategy())
app.use('authentication', authentication)
app.use(
'users',
memory({
multi: ['create'],
paginate: {
default: 10,
max: 20
}
})
)
app.service('users').hooks([protect('password')])
app.service('users').hooks({
create: [hashPassword('password')],
get: [
async (context, next) => {
await next()
if (context.params.provider) {
context.result.fromGet = true
}
}
]
})
return app
}