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

Commit 302717f

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

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

src/verifier.js

Lines changed: 5 additions & 2 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,15 @@ class LocalVerifier {
6465

6566
verify(req, username, password, done) {
6667
debug('Checking credentials', username, password);
67-
const query = {
68+
const params = omit(req.params || {}, 'query', 'provider', 'headers', 'session', 'cookies');
69+
params.query = {
6870
[this.options.usernameField]: username,
6971
$limit: 1
7072
};
73+
console.log('Params: ', params);
7174

7275
// Look up the entity
73-
this.service.find({ query })
76+
this.service.find(params)
7477
.then(this._normalizeResult)
7578
.then(entity => this._comparePassword(entity, password))
7679
.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)