Skip to content

Commit e1939be

Browse files
authored
fix(authentication): Retain object references in authenticate hook (#1675)
1 parent 1ebc58e commit e1939be

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

packages/authentication/src/hooks/authenticate.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { flatten, omit, merge } from 'lodash';
1+
import { flatten, omit } from 'lodash';
22
import { HookContext } from '@feathersjs/feathers';
33
import { NotAuthenticated } from '@feathersjs/errors';
44
import Debug from 'debug';
@@ -51,7 +51,7 @@ export default (originalSettings: string | AuthenticateHookSettings, ...original
5151

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

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

5656
return context;
5757
} else if (provider) {

packages/authentication/src/jwt.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ export class JWTStrategy extends AuthenticationBaseStrategy {
112112
accessToken,
113113
authentication: {
114114
strategy: 'jwt',
115+
accessToken,
115116
payload
116117
}
117118
};

packages/authentication/test/hooks/authenticate.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,29 @@ describe('authentication/hooks/authenticate', () => {
112112
assert.deepStrictEqual(result, Object.assign({}, params, Strategy1.result));
113113
});
114114

115+
it('authenticates with first strategy, keeps references alive (#1629)', async () => {
116+
const connection = {};
117+
const params = {
118+
connection,
119+
authentication: {
120+
strategy: 'first',
121+
username: 'David'
122+
}
123+
};
124+
125+
app.service('users').hooks({
126+
after: {
127+
get: context => {
128+
context.result.params = context.params;
129+
}
130+
}
131+
});
132+
133+
const result = await app.service('users').get(1, params);
134+
135+
assert.ok(result.params.connection === connection);
136+
});
137+
115138
it('authenticates with different authentication service', async () => {
116139
const params = {
117140
authentication: {

0 commit comments

Comments
 (0)