-
-
Notifications
You must be signed in to change notification settings - Fork 795
Expand file tree
/
Copy pathfixture.ts
More file actions
57 lines (48 loc) · 1.34 KB
/
fixture.ts
File metadata and controls
57 lines (48 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { feathers } from '@feathersjs/feathers';
import { memory, Service as MemoryService } from '@feathersjs/adapter-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({
before: {
create: [ hashPassword('password') ]
},
after: {
all: [ protect('password') ],
get: [context => {
if (context.params.provider) {
context.result.fromGet = true;
}
return context;
}]
}
});
return app;
}