diff options
author | eug-vs <eug-vs@keemail.me> | 2020-11-15 03:46:51 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2020-11-15 03:46:51 +0300 |
commit | 7da6c6a8e4a3590dfb8569b9fc24b4054552c96f (patch) | |
tree | 7e698115c9fc07767a7c4565e64174441d5d67db /src/services/auth/auth.service.js | |
parent | d113caace46ee53b86a31da2879d991562de45a1 (diff) | |
download | bsu-fantom-7da6c6a8e4a3590dfb8569b9fc24b4054552c96f.tar.gz |
feat: setup authentication
Diffstat (limited to 'src/services/auth/auth.service.js')
-rw-r--r-- | src/services/auth/auth.service.js | 22 |
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); +}; + |