Skip to content

Commit

Permalink
fix(authentication): Retain object references in authenticate hook (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl committed Nov 11, 2019
1 parent 1ebc58e commit e1939be
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/authentication/src/hooks/authenticate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { flatten, omit, merge } from 'lodash';
import { flatten, omit } from 'lodash';
import { HookContext } from '@feathersjs/feathers';
import { NotAuthenticated } from '@feathersjs/errors';
import Debug from 'debug';
Expand Down Expand Up @@ -51,7 +51,7 @@ export default (originalSettings: string | AuthenticateHookSettings, ...original

const authResult = await authService.authenticate(authentication, authParams, ...strategies);

context.params = merge({}, params, omit(authResult, 'accessToken'), { authenticated: true });
context.params = Object.assign({}, params, omit(authResult, 'accessToken'), { authenticated: true });

return context;
} else if (provider) {
Expand Down
1 change: 1 addition & 0 deletions packages/authentication/src/jwt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export class JWTStrategy extends AuthenticationBaseStrategy {
accessToken,
authentication: {
strategy: 'jwt',
accessToken,
payload
}
};
Expand Down
23 changes: 23 additions & 0 deletions packages/authentication/test/hooks/authenticate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,29 @@ describe('authentication/hooks/authenticate', () => {
assert.deepStrictEqual(result, Object.assign({}, params, Strategy1.result));
});

it('authenticates with first strategy, keeps references alive (#1629)', async () => {
const connection = {};
const params = {
connection,
authentication: {
strategy: 'first',
username: 'David'
}
};

app.service('users').hooks({
after: {
get: context => {
context.result.params = context.params;
}
}
});

const result = await app.service('users').get(1, params);

assert.ok(result.params.connection === connection);
});

it('authenticates with different authentication service', async () => {
const params = {
authentication: {
Expand Down

0 comments on commit e1939be

Please sign in to comment.