From f9be3002db666099ce6a2ab8ea04e6356bc20e3a Mon Sep 17 00:00:00 2001 From: Sergio Gutierrez Villalba Date: Wed, 26 Jun 2024 15:46:24 +0200 Subject: [PATCH] fix(user): save one database call in user refresh --- src/app/routes/routes.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/app/routes/routes.ts b/src/app/routes/routes.ts index 89ae6394..4fb54168 100644 --- a/src/app/routes/routes.ts +++ b/src/app/routes/routes.ts @@ -56,17 +56,18 @@ export default (router: Router, service: any, App: any): Router => { const { publicKey, privateKey, revocateKey } = req.body; const userData: any = (req as AuthorizedUser).user; - const keyExists = await service.KeyServer.keysExists(userData); + let [keys, userBucket] = await Promise.all([ + service.KeyServer.getKeys(userData), + service.User.GetUserBucket(userData), + ]); + + const keyExists = !!keys; if (!keyExists && publicKey) { await service.KeyServer.addKeysLogin(userData, publicKey, privateKey, revocateKey); + keys = await service.KeyServer.getKeys(userData); } - const [keys, userBucket] = await Promise.all([ - service.KeyServer.getKeys(userData), - service.User.GetUserBucket(userData), - ]); - const token = Sign(userData.email, App.config.get('secrets').JWT, true); const user = {