Skip to content

Commit 64c78e7

Browse files
committed
feat: add handle side effect function to authinfo
@W-0@
1 parent 9fe5ef3 commit 64c78e7

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/exported.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export {
3232

3333
export { ConfigInfo, ConfigAggregator } from './config/configAggregator';
3434

35-
export { AuthFields, AuthInfo, OrgAuthorization } from './org/authInfo';
35+
export { AuthFields, AuthInfo, AuthSideEffects, OrgAuthorization } from './org/authInfo';
3636

3737
export { AuthRemover } from './org/authRemover';
3838

src/org/authInfo.ts

+20
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ export interface AccessTokenOptions {
113113
instanceUrl?: string;
114114
}
115115

116+
export type AuthSideEffects = {
117+
alias: string;
118+
setDefault: boolean;
119+
setDefaultDevHub: boolean;
120+
};
121+
116122
type UserInfo = AnyJson & {
117123
username: string;
118124
organizationId: string;
@@ -563,6 +569,20 @@ export class AuthInfo extends AsyncOptionalCreatable<AuthInfo.Options> {
563569
return sfdxAuthUrl;
564570
}
565571

572+
/**
573+
* Convenience function to handle typical side effects encountered when dealing with an AuthInfo.
574+
* Given the values supplied in parameter sideEffects, this functions will set auth alias, default auth
575+
* and default dev hub.
576+
*
577+
* @param sideEffects - instance of AuthSideEffects
578+
*/
579+
public async handleSideEffects(sideEffects: AuthSideEffects): Promise<void> {
580+
if (sideEffects.alias) await this.setAlias(sideEffects.alias);
581+
if (sideEffects.setDefault) await this.setAsDefault({ org: true });
582+
if (sideEffects.setDefaultDevHub) await this.setAsDefault({ devHub: true });
583+
await this.save();
584+
}
585+
566586
/**
567587
* Set the target-env (default) or the target-dev-hub to the alias if
568588
* it exists otherwise to the username. Method will try to set the local

0 commit comments

Comments
 (0)