auth: Remove userName parameter of removeToken function

As suggested by @innaytool

Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
Philip Molares 2021-01-23 22:24:59 +01:00
parent f68caab6e8
commit cc2fcac532
3 changed files with 4 additions and 6 deletions

View file

@ -48,7 +48,6 @@ export class TokensController {
@Delete('/:keyId') @Delete('/:keyId')
@HttpCode(204) @HttpCode(204)
async deleteToken(@Param('keyId') keyId: string) { async deleteToken(@Param('keyId') keyId: string) {
// ToDo: Get real userName return this.authService.removeToken(keyId);
return this.authService.removeToken('hardcoded', keyId);
} }
} }

View file

@ -152,7 +152,7 @@ describe('AuthService', () => {
describe('removeToken', () => { describe('removeToken', () => {
it('works', async () => { it('works', async () => {
await service.removeToken(user.userName, authToken.keyId); await service.removeToken(authToken.keyId);
}); });
}); });

View file

@ -141,10 +141,9 @@ export class AuthService {
return user.authTokens; return user.authTokens;
} }
async removeToken(userName: string, keyId: string) { async removeToken(keyId: string) {
const user = await this.usersService.getUserByUsername(userName);
const token = await this.authTokenRepository.findOne({ const token = await this.authTokenRepository.findOne({
where: { keyId: keyId, user: user }, where: { keyId: keyId },
}); });
await this.authTokenRepository.remove(token); await this.authTokenRepository.remove(token);
} }