Skip to content
This repository has been archived by the owner on Aug 29, 2018. It is now read-only.

Commit

Permalink
Resolves #14 - Passes Feathers params to service hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-p-wilson committed May 14, 2017
1 parent b0af3ab commit 79075da
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
14 changes: 9 additions & 5 deletions src/verifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Debug from 'debug';
import errors from 'feathers-errors';
import bcrypt from 'bcryptjs';
import get from 'lodash.get';
import omit from 'lodash.omit';

const debug = Debug('feathers-authentication-local:verify');

Expand Down Expand Up @@ -64,13 +65,16 @@ class LocalVerifier {

verify(req, username, password, done) {
debug('Checking credentials', username, password);
const query = {
[this.options.usernameField]: username,
$limit: 1
};
const params = Object.assign({
'query': {
[this.options.usernameField]: username,
'$limit': 1
}
}, omit(req.params, 'query', 'provider', 'headers', 'session', 'cookies'));
console.log('Params: ', params);

// Look up the entity
this.service.find({ query })
this.service.find(params)
.then(this._normalizeResult)
.then(entity => this._comparePassword(entity, password))
.then(entity => {
Expand Down
18 changes: 17 additions & 1 deletion test/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,20 @@ describe('integration', () => {
query: {},
body: Object.assign({}, User),
headers: {},
cookies: {}
cookies: {},
params: {
query: {},
provider: 'socketio',
headers: {},
session: {},
cookies: {},
data: 'Hello, world'
}
};

const app = feathers();
let paramsReceived = false;
let dataReceived;

app.configure(hooks())
.configure(authentication({ secret: 'secret' }))
Expand All @@ -28,6 +38,10 @@ describe('integration', () => {

app.service('users').hooks({
before: {
find: (hook) => {
paramsReceived = Object.keys(hook.params);
dataReceived = hook.params.data;
},
create: local.hooks.hashPassword({ passwordField: 'password' })
}
});
Expand All @@ -39,6 +53,8 @@ describe('integration', () => {
expect(result.success).to.equal(true);
expect(result.data.user.email).to.equal(User.email);
expect(result.data.user.password).to.not.equal(undefined);
expect(paramsReceived).to.have.members(['data', 'query']);
expect(dataReceived).to.equal('Hello, world');
});
});
});
Expand Down

0 comments on commit 79075da

Please sign in to comment.