Skip to content

Commit

Permalink
fix: consider users that have already been issued a derived key (#271)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackson-dean authored Sep 22, 2023
1 parent f81736c commit 4dc3c26
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ export class AppComponent implements OnInit {
this.globalVars.getFreeDeso = true;
}

const authenticatedUsers = new Set(
params.get('authenticatedUsers')?.split(',') ?? []
);
if (authenticatedUsers.size > 0) {
this.globalVars.authenticatedUsers = authenticatedUsers;
}

if (params.get('subAccounts') === 'true') {
this.globalVars.subAccounts = true;
}
Expand Down
13 changes: 13 additions & 0 deletions src/app/derive/derive.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,19 @@ export class DeriveComponent implements OnInit {
});
return;
}

// If this user has already approved a derived key for login, then we can just log them in
// without approval.
if (this.globalVars.authenticatedUsers.has(publicKey)) {
this.identityService.login({
users: this.accountService.getEncryptedUsers(),
publicKeyAdded: publicKey,
});

return;
}

// Otherwise, setting the public key will trigger the approval UI to show.
this.publicKeyBase58Check = publicKey;
});
}
Expand Down
9 changes: 9 additions & 0 deletions src/app/global-vars.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ export class GlobalVarsService {
*/
subAccounts: boolean = false;

/**
* Set of public keys that have been authenticated by the calling application.
* This is used as a hint to decide whether to show the derived key approval
* UI or not after the user selects an account to login with. If the account
* they select is provided in this set, then we skip the approval UI and issue
* a plain login payload.
*/
authenticatedUsers: Set<string> = new Set();

isFullAccessHostname(): boolean {
return GlobalVarsService.fullAccessHostnames.includes(this.hostname);
}
Expand Down

0 comments on commit 4dc3c26

Please sign in to comment.