From cb59d63a8262bc3cf6d2a001daf536012b3be813 Mon Sep 17 00:00:00 2001 From: Bernd Storath Date: Wed, 3 Jun 2026 10:57:10 +0200 Subject: [PATCH] remove type assertion --- src/server/database/repositories/user/service.ts | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/server/database/repositories/user/service.ts b/src/server/database/repositories/user/service.ts index 0113478a..cecf0df8 100644 --- a/src/server/database/repositories/user/service.ts +++ b/src/server/database/repositories/user/service.ts @@ -58,14 +58,14 @@ export class UserService { this.#statements = createPreparedStatement(db); } - #createTotp(user: Pick) { + #createTotp(user: { username: string; totpKey: string }) { return new TOTP({ issuer: 'wg-easy', label: user.username, algorithm: 'SHA1', digits: 6, period: 30, - secret: user.totpKey!, + secret: user.totpKey, }); } @@ -167,11 +167,12 @@ export class UserService { if (!code) { return { success: false, error: 'TOTP_REQUIRED' }; } else { - if (!txUser.totpKey) { + const totpKey = txUser.totpKey; + if (!totpKey) { return { success: false, error: 'UNEXPECTED_ERROR' }; } - const totp = this.#createTotp(txUser); + const totp = this.#createTotp({ username: txUser.username, totpKey }); if (totp.validate({ token: code, window: 1 }) === null) { return { success: false, error: 'INVALID_TOTP_CODE' }; } @@ -196,11 +197,12 @@ export class UserService { throw new Error('User not found'); } - if (!txUser.totpKey) { + const totpKey = txUser.totpKey; + if (!totpKey) { throw new Error('TOTP key is not set'); } - const totp = this.#createTotp(txUser); + const totp = this.#createTotp({ username: txUser.username, totpKey }); if (totp.validate({ token: code, window: 1 }) === null) { throw new Error('Invalid TOTP code'); }