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 = {