summaryrefslogtreecommitdiff
path: root/src/services/auth/auth.service.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/services/auth/auth.service.js')
-rw-r--r--src/services/auth/auth.service.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/services/auth/auth.service.js b/src/services/auth/auth.service.js
new file mode 100644
index 0000000..9e92a02
--- /dev/null
+++ b/src/services/auth/auth.service.js
@@ -0,0 +1,22 @@
+const { AuthenticationService, JWTStrategy } = require('@feathersjs/authentication');
+const { LocalStrategy } = require('@feathersjs/authentication-local');
+const _ = require('lodash');
+
+class NoHashingLocalStrategy extends LocalStrategy {
+ async comparePassword (entity, password) {
+ const { entityPasswordField, errorMessage } = this.configuration;
+ const entityPassword = _.get(entity, entityPasswordField);
+ if (entityPassword !== password) throw new Error(errorMessage);
+ return entity;
+ }
+}
+
+module.exports = app => {
+ const authentication = new AuthenticationService(app);
+
+ authentication.register('local', new NoHashingLocalStrategy());
+ authentication.register('jwt', new JWTStrategy());
+
+ app.use('/authentication', authentication);
+};
+