From da649d75c079d983231e3606402b5deeb0fc4195 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Wed, 9 Apr 2025 09:43:38 +0200 Subject: [PATCH] refactor(routes/api/recovery_codes): use Array.from with mapFn in generateRecoveryCodes gives us the identical result as before, but a lot more concise and "DRY" --- src/routes/api/recovery_codes.ts | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/routes/api/recovery_codes.ts b/src/routes/api/recovery_codes.ts index 848820981..4ff80614b 100644 --- a/src/routes/api/recovery_codes.ts +++ b/src/routes/api/recovery_codes.ts @@ -20,16 +20,7 @@ function checkForRecoveryKeys() { } function generateRecoveryCodes() { - const recoveryKeys = [ - randomBytes(16).toString('base64'), - randomBytes(16).toString('base64'), - randomBytes(16).toString('base64'), - randomBytes(16).toString('base64'), - randomBytes(16).toString('base64'), - randomBytes(16).toString('base64'), - randomBytes(16).toString('base64'), - randomBytes(16).toString('base64') - ]; + const recoveryKeys = Array.from({ length: 8 }, () => randomBytes(16).toString('base64')); recovery_codes.setRecoveryCodes(recoveryKeys.join(','));