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

Commit 79075da

Browse files
Resolves #14 - Passes Feathers params to service hooks
1 parent b0af3ab commit 79075da

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

src/verifier.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Debug from 'debug';
22
import errors from 'feathers-errors';
33
import bcrypt from 'bcryptjs';
44
import get from 'lodash.get';
5+
import omit from 'lodash.omit';
56

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

@@ -64,13 +65,16 @@ class LocalVerifier {
6465

6566
verify(req, username, password, done) {
6667
debug('Checking credentials', username, password);
67-
const query = {
68-
[this.options.usernameField]: username,
69-
$limit: 1
70-
};
68+
const params = Object.assign({
69+
'query': {
70+
[this.options.usernameField]: username,
71+
'$limit': 1
72+
}
73+
}, omit(req.params, 'query', 'provider', 'headers', 'session', 'cookies'));
74+
console.log('Params: ', params);
7175

7276
// Look up the entity
73-
this.service.find({ query })
77+
this.service.find(params)
7478
.then(this._normalizeResult)
7579
.then(entity => this._comparePassword(entity, password))
7680
.then(entity => {

test/integration.test.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,20 @@ describe('integration', () => {
1616
query: {},
1717
body: Object.assign({}, User),
1818
headers: {},
19-
cookies: {}
19+
cookies: {},
20+
params: {
21+
query: {},
22+
provider: 'socketio',
23+
headers: {},
24+
session: {},
25+
cookies: {},
26+
data: 'Hello, world'
27+
}
2028
};
2129

2230
const app = feathers();
31+
let paramsReceived = false;
32+
let dataReceived;
2333

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

2939
app.service('users').hooks({
3040
before: {
41+
find: (hook) => {
42+
paramsReceived = Object.keys(hook.params);
43+
dataReceived = hook.params.data;
44+
},
3145
create: local.hooks.hashPassword({ passwordField: 'password' })
3246
}
3347
});
@@ -39,6 +53,8 @@ describe('integration', () => {
3953
expect(result.success).to.equal(true);
4054
expect(result.data.user.email).to.equal(User.email);
4155
expect(result.data.user.password).to.not.equal(undefined);
56+
expect(paramsReceived).to.have.members(['data', 'query']);
57+
expect(dataReceived).to.equal('Hello, world');
4258
});
4359
});
4460
});

0 commit comments

Comments
 (0)