Skip to content

Commit

Permalink
fix: Set authenticated: true after successful authentication (#1367)
Browse files Browse the repository at this point in the history
  • Loading branch information
KidkArolis authored and daffl committed May 25, 2019
1 parent 1a92f53 commit 9918cff
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/authentication/src/hooks/authenticate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default (originalSettings: string|AuthenticateHookSettings, ...originalSt

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

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

return context;
} else if (!authentication && provider) {
Expand Down
6 changes: 4 additions & 2 deletions packages/authentication/test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ export class Strategy1 extends AuthenticationBaseStrategy {
user: {
id: 123,
name: 'Dave'
}
},
authenticated: true
};

async authenticate (authentication: AuthenticationRequest) {
Expand All @@ -40,7 +41,8 @@ export class Strategy2 extends AuthenticationBaseStrategy {
user: {
name: 'V2',
version: 2
}
},
authenticated: true
};

authenticate (authentication: AuthenticationRequest, params: Params) {
Expand Down
10 changes: 6 additions & 4 deletions packages/authentication/test/jwt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,14 @@ describe('authentication/jwt', () => {

const result = await app.service('protected').get('test', params);

assert.strictEqual(Object.keys(result.params).length, 3);
assert.strictEqual(Object.keys(result.params).length, 4);
assert.ok(!result.params.accessToken, 'Did not merge accessToken');
assert.deepStrictEqual(result, {
id: 'test',
params: merge({}, params, {
user,
authentication: { payload }
authentication: { payload },
authenticated: true
})
});
});
Expand All @@ -186,12 +187,13 @@ describe('authentication/jwt', () => {

const result = await app.service('protected').get('test', params);

assert.strictEqual(Object.keys(result.params).length, 2);
assert.strictEqual(Object.keys(result.params).length, 3);
assert.ok(!result.params.accessToken, 'Did not merge accessToken');
assert.deepStrictEqual(result, {
id: 'test',
params: merge({}, params, {
authentication: { payload }
authentication: { payload },
authenticated: true
})
});
});
Expand Down

0 comments on commit 9918cff

Please # to comment.