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

Commit 7e12a27

Browse files
Merge pull request #15 from intellect-collective/fix/14-feathers-params-service-hooks
Resolves #14 - Passes Feathers params to service hooks
2 parents dffae0b + cff3852 commit 7e12a27

2 files changed

Lines changed: 26 additions & 7 deletions

File tree

src/verifier.js

Lines changed: 9 additions & 6 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

@@ -71,17 +72,19 @@ class LocalVerifier {
7172
// Choose username field
7273
const usernameField = this.options.entityUsernameField || this.options.usernameField;
7374

74-
const query = {
75-
[usernameField]: username,
76-
$limit: 1
77-
};
75+
const params = Object.assign({
76+
'query': {
77+
[usernameField]: username,
78+
'$limit': 1
79+
}
80+
}, omit(req.params, 'query', 'provider', 'headers', 'session', 'cookies'));
7881

7982
// Look up the entity
80-
this.service.find({ query })
83+
this.service.find(params)
8184
.then(response => {
8285
const results = response.data || response
8386
if (!results.length) {
84-
debug(`a record with ${this.options.usernameField} of '${username}' did not exist`);
87+
debug(`a record with ${usernameField} of '${username}' did not exist`);
8588
}
8689
return this._normalizeResult(response)
8790
})

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)