From cc2fcac5322c1db1dfaac550628ec2138bd342de Mon Sep 17 00:00:00 2001 From: Philip Molares Date: Sat, 23 Jan 2021 22:24:59 +0100 Subject: [PATCH] auth: Remove userName parameter of removeToken function As suggested by @innaytool Signed-off-by: Philip Molares --- src/api/private/tokens/tokens.controller.ts | 3 +-- src/auth/auth.service.spec.ts | 2 +- src/auth/auth.service.ts | 5 ++--- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/api/private/tokens/tokens.controller.ts b/src/api/private/tokens/tokens.controller.ts index 780e11be2..af2aa792f 100644 --- a/src/api/private/tokens/tokens.controller.ts +++ b/src/api/private/tokens/tokens.controller.ts @@ -48,7 +48,6 @@ export class TokensController { @Delete('/:keyId') @HttpCode(204) async deleteToken(@Param('keyId') keyId: string) { - // ToDo: Get real userName - return this.authService.removeToken('hardcoded', keyId); + return this.authService.removeToken(keyId); } } diff --git a/src/auth/auth.service.spec.ts b/src/auth/auth.service.spec.ts index e5375e15d..ae57414a3 100644 --- a/src/auth/auth.service.spec.ts +++ b/src/auth/auth.service.spec.ts @@ -152,7 +152,7 @@ describe('AuthService', () => { describe('removeToken', () => { it('works', async () => { - await service.removeToken(user.userName, authToken.keyId); + await service.removeToken(authToken.keyId); }); }); diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index 10a427ced..e37535104 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -141,10 +141,9 @@ export class AuthService { return user.authTokens; } - async removeToken(userName: string, keyId: string) { - const user = await this.usersService.getUserByUsername(userName); + async removeToken(keyId: string) { const token = await this.authTokenRepository.findOne({ - where: { keyId: keyId, user: user }, + where: { keyId: keyId }, }); await this.authTokenRepository.remove(token); }