From 5b587cff62b584fb5896f910f03f28f80cc28c54 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sun, 14 Jun 2020 17:05:34 +0300 Subject: feat: create auth service --- services/auth/auth.service.ts | 16 ++++++++++++++++ services/index.ts | 2 ++ 2 files changed, 18 insertions(+) create mode 100644 services/auth/auth.service.ts (limited to 'services') diff --git a/services/auth/auth.service.ts b/services/auth/auth.service.ts new file mode 100644 index 0000000..42846b0 --- /dev/null +++ b/services/auth/auth.service.ts @@ -0,0 +1,16 @@ +import { + AuthenticationService, + JWTStrategy +} from '@feathersjs/authentication'; +import { LocalStrategy } from '@feathersjs/authentication-local'; +import { Application } from '@feathersjs/express'; + +export default (app: Application): void => { + const authentication = new AuthenticationService(app); + + authentication.register('local', new LocalStrategy()); + authentication.register('jwt', new JWTStrategy()); + + app.use('/authentication', authentication); +}; + diff --git a/services/index.ts b/services/index.ts index d946e9d..f000837 100644 --- a/services/index.ts +++ b/services/index.ts @@ -2,8 +2,10 @@ import { Application } from '@feathersjs/express'; import Users from './users/users.service'; import Polls from './polls/polls.service'; import Profiles from './profiles/profiles.service'; +import Auth from './auth/auth.service'; export default (app: Application): void => { + app.configure(Auth); app.configure(Users); app.configure(Polls); app.configure(Profiles); -- cgit v1.2.3 From fc4bdecdcd8abc7a2adaeb4b7f209f6930846ffa Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sun, 14 Jun 2020 17:09:19 +0300 Subject: feat: use hashPassword hook --- services/users/users.hooks.ts | 12 ++++++++++++ services/users/users.service.ts | 2 ++ 2 files changed, 14 insertions(+) create mode 100644 services/users/users.hooks.ts (limited to 'services') diff --git a/services/users/users.hooks.ts b/services/users/users.hooks.ts new file mode 100644 index 0000000..06cbfde --- /dev/null +++ b/services/users/users.hooks.ts @@ -0,0 +1,12 @@ +import { hooks } from '@feathersjs/authentication-local'; + +const hashPassword = hooks.hashPassword('password'); + +export default { + before: { + create: [hashPassword], + patch: [hashPassword], + update: [hashPassword] + } +}; + diff --git a/services/users/users.service.ts b/services/users/users.service.ts index 988d162..08c347d 100644 --- a/services/users/users.service.ts +++ b/services/users/users.service.ts @@ -1,10 +1,12 @@ import { Application } from '@feathersjs/express'; import service from 'feathers-mongoose'; import Model from '../../models/users/user.model'; +import hooks from './users.hooks'; const UserService = service({ Model }); export default (app: Application): void => { app.use('/users', UserService); + app.service('users').hooks(hooks); }; -- cgit v1.2.3 From 1ab199588d5353d98d49172e1f35d73452069faf Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sun, 14 Jun 2020 17:13:40 +0300 Subject: feat: protect password field --- services/users/users.hooks.ts | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'services') diff --git a/services/users/users.hooks.ts b/services/users/users.hooks.ts index 06cbfde..fc17ed7 100644 --- a/services/users/users.hooks.ts +++ b/services/users/users.hooks.ts @@ -1,8 +1,12 @@ import { hooks } from '@feathersjs/authentication-local'; const hashPassword = hooks.hashPassword('password'); +const protectPassword = hooks.protect('password'); export default { + after: { + all: [protectPassword] + }, before: { create: [hashPassword], patch: [hashPassword], -- cgit v1.2.3