From 7da6c6a8e4a3590dfb8569b9fc24b4054552c96f Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sun, 15 Nov 2020 03:46:51 +0300 Subject: feat: setup authentication --- src/services/auth/auth.service.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/services/auth/auth.service.js (limited to 'src/services/auth/auth.service.js') 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); +}; + -- cgit v1.2.3