aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/services
diff options
context:
space:
mode:
Diffstat (limited to 'src/services')
-rw-r--r--src/services/index.js4
-rw-r--r--src/services/posts/posts.hooks.js33
-rw-r--r--src/services/posts/posts.service.js22
-rw-r--r--src/services/users/users.hooks.js41
-rw-r--r--src/services/users/users.service.js22
5 files changed, 122 insertions, 0 deletions
diff --git a/src/services/index.js b/src/services/index.js
index 791edad..ccbb889 100644
--- a/src/services/index.js
+++ b/src/services/index.js
@@ -1,3 +1,7 @@
+const posts = require('./posts/posts.service.js');
+const users = require('./users/users.service.js');
// eslint-disable-next-line no-unused-vars
module.exports = function (app) {
+ app.configure(posts);
+ app.configure(users);
};
diff --git a/src/services/posts/posts.hooks.js b/src/services/posts/posts.hooks.js
new file mode 100644
index 0000000..39ac996
--- /dev/null
+++ b/src/services/posts/posts.hooks.js
@@ -0,0 +1,33 @@
+const {authenticate} = require('@feathersjs/authentication').hooks;
+
+module.exports = {
+ before: {
+ all: [authenticate('jwt')],
+ find: [],
+ get: [],
+ create: [],
+ update: [],
+ patch: [],
+ remove: []
+ },
+
+ after: {
+ all: [],
+ find: [],
+ get: [],
+ create: [],
+ update: [],
+ patch: [],
+ remove: []
+ },
+
+ error: {
+ all: [],
+ find: [],
+ get: [],
+ create: [],
+ update: [],
+ patch: [],
+ remove: []
+ }
+};
diff --git a/src/services/posts/posts.service.js b/src/services/posts/posts.service.js
new file mode 100644
index 0000000..cacde6e
--- /dev/null
+++ b/src/services/posts/posts.service.js
@@ -0,0 +1,22 @@
+// Initializes the `posts` service on path `/posts`
+const createService = require('feathers-sequelize');
+const createModel = require('../../models/posts.model');
+const hooks = require('./posts.hooks');
+
+module.exports = function (app) {
+ const Model = createModel(app);
+ const paginate = app.get('paginate');
+
+ const options = {
+ Model,
+ paginate
+ };
+
+ // Initialize our service with any options it requires
+ app.use('/posts', createService(options));
+
+ // Get our initialized service so that we can register hooks
+ const service = app.service('posts');
+
+ service.hooks(hooks);
+};
diff --git a/src/services/users/users.hooks.js b/src/services/users/users.hooks.js
new file mode 100644
index 0000000..613676b
--- /dev/null
+++ b/src/services/users/users.hooks.js
@@ -0,0 +1,41 @@
+const { authenticate } = require('@feathersjs/authentication').hooks;
+
+const {
+ hashPassword, protect
+} = require('@feathersjs/authentication-local').hooks;
+
+module.exports = {
+ before: {
+ all: [],
+ find: [ authenticate('jwt') ],
+ get: [ authenticate('jwt') ],
+ create: [ hashPassword() ],
+ update: [ hashPassword(), authenticate('jwt') ],
+ patch: [ hashPassword(), authenticate('jwt') ],
+ remove: [ authenticate('jwt') ]
+ },
+
+ after: {
+ all: [
+ // Make sure the password field is never sent to the client
+ // Always must be the last hook
+ protect('password')
+ ],
+ find: [],
+ get: [],
+ create: [],
+ update: [],
+ patch: [],
+ remove: []
+ },
+
+ error: {
+ all: [],
+ find: [],
+ get: [],
+ create: [],
+ update: [],
+ patch: [],
+ remove: []
+ }
+};
diff --git a/src/services/users/users.service.js b/src/services/users/users.service.js
new file mode 100644
index 0000000..3cb0535
--- /dev/null
+++ b/src/services/users/users.service.js
@@ -0,0 +1,22 @@
+// Initializes the `users` service on path `/users`
+const createService = require('feathers-sequelize');
+const createModel = require('../../models/users.model');
+const hooks = require('./users.hooks');
+
+module.exports = function (app) {
+ const Model = createModel(app);
+ const paginate = app.get('paginate');
+
+ const options = {
+ Model,
+ paginate
+ };
+
+ // Initialize our service with any options it requires
+ app.use('/users', createService(options));
+
+ // Get our initialized service so that we can register hooks
+ const service = app.service('users');
+
+ service.hooks(hooks);
+};