@feathersjs/authentication-local
Advanced tools
Comparing version 1.0.1 to 1.0.2
# Change Log | ||
## [v1.0.1](https://github.com/feathersjs/authentication-local/tree/v1.0.1) (2017-11-16) | ||
[Full Changelog](https://github.com/feathersjs/authentication-local/compare/v1.0.0...v1.0.1) | ||
**Merged pull requests:** | ||
- Add default export for better ES module \(TypeScript\) compatibility [\#43](https://github.com/feathersjs/authentication-local/pull/43) ([daffl](https://github.com/daffl)) | ||
- Update @feathersjs/authentication to the latest version 🚀 [\#42](https://github.com/feathersjs/authentication-local/pull/42) ([greenkeeper[bot]](https://github.com/apps/greenkeeper)) | ||
## [v1.0.0](https://github.com/feathersjs/authentication-local/tree/v1.0.0) (2017-11-01) | ||
@@ -4,0 +12,0 @@ [Full Changelog](https://github.com/feathersjs/authentication-local/compare/v1.0.0-pre.2...v1.0.0) |
@@ -8,8 +8,8 @@ const hasher = require('../utils/hash'); | ||
module.exports = function hashPassword (options = {}) { | ||
return function (hook) { | ||
if (hook.type !== 'before') { | ||
return function (context) { | ||
if (context.type !== 'before') { | ||
return Promise.reject(new Error(`The 'hashPassword' hook should only be used as a 'before' hook.`)); | ||
} | ||
const app = hook.app; | ||
const app = context.app; | ||
const authOptions = app.get('authentication') || {}; | ||
@@ -32,5 +32,5 @@ | ||
if (hook.data === undefined) { | ||
if (context.data === undefined) { | ||
debug(`hook.data is undefined. Skipping hashPassword hook.`); | ||
return Promise.resolve(hook); | ||
return Promise.resolve(context); | ||
} | ||
@@ -41,8 +41,8 @@ | ||
// make sure we actually have password fields | ||
if (Array.isArray(hook.data)) { | ||
data = hook.data.filter(item => { | ||
if (Array.isArray(context.data)) { | ||
data = context.data.filter(item => { | ||
return item.hasOwnProperty(field); | ||
}); | ||
} else if (hook.data[field]) { | ||
data = hook.data; | ||
} else if (context.data[field]) { | ||
data = context.data; | ||
} | ||
@@ -54,3 +54,3 @@ | ||
debug(`'${field}' field is missing. Skipping hashPassword hook.`); | ||
return Promise.resolve(hook); | ||
return Promise.resolve(context); | ||
} | ||
@@ -68,4 +68,4 @@ | ||
.then(results => { | ||
hook.data = results; | ||
return Promise.resolve(hook); | ||
context.data = results; | ||
return Promise.resolve(context); | ||
}); | ||
@@ -76,6 +76,6 @@ } | ||
return hashPw(data[field]).then(hashedPassword => { | ||
hook.data[field] = hashedPassword; | ||
return Promise.resolve(hook); | ||
context.data[field] = hashedPassword; | ||
return Promise.resolve(context); | ||
}); | ||
}; | ||
}; |
const omit = require('lodash.omit'); | ||
module.exports = function (...fields) { | ||
return function protect (hook) { | ||
const result = hook.dispatch || hook.result; | ||
return function protect (context) { | ||
const result = context.dispatch || context.result; | ||
const o = current => omit(current, fields); | ||
if (!result) { | ||
return hook; | ||
return context; | ||
} | ||
if (Array.isArray(result)) { | ||
hook.dispatch = result.map(o); | ||
context.dispatch = result.map(o); | ||
} else if (result.data) { | ||
hook.dispatch = Object.assign({}, result, { | ||
context.dispatch = Object.assign({}, result, { | ||
data: result.data.map(o) | ||
}); | ||
} else { | ||
hook.dispatch = o(result); | ||
context.dispatch = o(result); | ||
} | ||
return hook; | ||
if (context.params && context.params.provider) { | ||
context.result = context.dispatch; | ||
} | ||
return context; | ||
}; | ||
}; |
{ | ||
"name": "@feathersjs/authentication-local", | ||
"description": "Local authentication strategy for @feathers/authentication", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"homepage": "https://github.com/feathersjs/authentication-local", | ||
@@ -68,3 +68,3 @@ "main": "lib/", | ||
"chai": "^4.0.2", | ||
"feathers-memory": "^1.1.0", | ||
"feathers-memory": "^2.0.0", | ||
"istanbul": "^1.1.0-alpha.1", | ||
@@ -71,0 +71,0 @@ "mocha": "^4.0.0", |
30535
306