aboutsummaryrefslogtreecommitdiff
path: root/services
diff options
context:
space:
mode:
authorEugene Sokolov <eug-vs@keemail.me>2020-06-14 18:07:37 +0300
committerGitHub <noreply@github.com>2020-06-14 18:07:37 +0300
commit52d3bfcecc2cfbaed8e65728124477131bc0d233 (patch)
tree5699ba9d7e16b89e6ebefaf49d6992bb3eb6f3cd /services
parent1860396a1286936374ab88937da3e0b6b9b1a36d (diff)
parent1ab199588d5353d98d49172e1f35d73452069faf (diff)
downloadwhich-api-52d3bfcecc2cfbaed8e65728124477131bc0d233.tar.gz
Merge pull request #7 from eug-vs/auth
Setup authentication
Diffstat (limited to 'services')
-rw-r--r--services/auth/auth.service.ts16
-rw-r--r--services/index.ts2
-rw-r--r--services/users/users.hooks.ts16
-rw-r--r--services/users/users.service.ts2
4 files changed, 36 insertions, 0 deletions
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);
diff --git a/services/users/users.hooks.ts b/services/users/users.hooks.ts
new file mode 100644
index 0000000..fc17ed7
--- /dev/null
+++ b/services/users/users.hooks.ts
@@ -0,0 +1,16 @@
+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],
+ 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);
};