Skip to content

Commit b5aa0ed

Browse files
authored
Conditonally call login_with_refresh_token (#810)
* Conditonally call login_with_refresh_token * lint fix * support for CO * pr comment
1 parent 288f398 commit b5aa0ed

File tree

1 file changed

+36
-14
lines changed

1 file changed

+36
-14
lines changed

src/app/auth/login/login.component.ts

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import { ClusterDomainWithToken } from 'src/app/core/models/misc/token.model';
1515
import { StorageService } from 'src/app/core/services/common/storage.service';
1616
import { NetsuiteAuthService } from 'src/app/core/services/netsuite/netsuite-core/netsuite-auth.service';
1717
import { XeroAuthService } from 'src/app/core/services/xero/xero-core/xero-auth.service';
18+
import { exposeAppConfig } from 'src/app/branding/expose-app-config';
19+
import { brandingConfig } from 'src/app/branding/branding-config';
1820

1921
@Component({
2022
selector: 'app-login',
@@ -23,6 +25,12 @@ import { XeroAuthService } from 'src/app/core/services/xero/xero-core/xero-auth.
2325
})
2426
export class LoginComponent implements OnInit {
2527

28+
readonly brandingConfig = brandingConfig;
29+
30+
readonly isINCluster = this.storageService.get('cluster-domain').includes('in1');
31+
32+
readonly exposeApps = !this.isINCluster ? exposeAppConfig[brandingConfig.brandId][brandingConfig.envId] : exposeAppConfig[brandingConfig.brandId]['production-1-in'];
33+
2634
constructor(
2735
private authService: AuthService,
2836
private businessCentralAuthService: BusinessCentralAuthService,
@@ -64,26 +72,40 @@ export class LoginComponent implements OnInit {
6472
};
6573
this.userService.storeUserProfile(user);
6674

67-
this.helperService.setBaseApiURL(AppUrl.QBD);
68-
this.qbdAuthService.qbdLogin(clusterDomainWithToken.tokens.refresh_token).subscribe();
75+
if (this.exposeApps.QBD) {
76+
this.helperService.setBaseApiURL(AppUrl.QBD);
77+
this.qbdAuthService.qbdLogin(clusterDomainWithToken.tokens.refresh_token).subscribe();
78+
}
6979

70-
this.helperService.setBaseApiURL(AppUrl.SAGE300);
71-
this.sage300AuthService.loginWithRefreshToken(clusterDomainWithToken.tokens.refresh_token).subscribe();
80+
if (this.exposeApps.SAGE300) {
81+
this.helperService.setBaseApiURL(AppUrl.SAGE300);
82+
this.sage300AuthService.loginWithRefreshToken(clusterDomainWithToken.tokens.refresh_token).subscribe();
83+
}
7284

73-
this.helperService.setBaseApiURL(AppUrl.BUSINESS_CENTRAL);
74-
this.businessCentralAuthService.loginWithRefreshToken(clusterDomainWithToken.tokens.refresh_token).subscribe();
85+
if (this.exposeApps.BUSINESS_CENTRAL) {
86+
this.helperService.setBaseApiURL(AppUrl.BUSINESS_CENTRAL);
87+
this.businessCentralAuthService.loginWithRefreshToken(clusterDomainWithToken.tokens.refresh_token).subscribe();
88+
}
7589

7690
// Only local dev needs this, login happens via postMessage for prod/staging through webapp
7791
if (!environment.production) {
7892
this.userService.storeUserProfile(user);
79-
this.helperService.setBaseApiURL(AppUrl.QBO);
80-
this.qboAuthService.loginWithRefreshToken(clusterDomainWithToken.tokens.refresh_token).subscribe();
81-
this.helperService.setBaseApiURL(AppUrl.INTACCT);
82-
this.siAuthService.loginWithRefreshToken(clusterDomainWithToken.tokens.refresh_token).subscribe();
83-
this.helperService.setBaseApiURL(AppUrl.NETSUITE);
84-
this.netsuiteAuthService.loginWithRefreshToken(clusterDomainWithToken.tokens.refresh_token).subscribe();
85-
this.helperService.setBaseApiURL(AppUrl.XERO);
86-
this.xeroAuthService.loginWithRefreshToken(clusterDomainWithToken.tokens.refresh_token).subscribe();
93+
if (this.exposeApps.QBO) {
94+
this.helperService.setBaseApiURL(AppUrl.QBO);
95+
this.qboAuthService.loginWithRefreshToken(clusterDomainWithToken.tokens.refresh_token).subscribe();
96+
}
97+
if (this.exposeApps.INTACCT) {
98+
this.helperService.setBaseApiURL(AppUrl.INTACCT);
99+
this.siAuthService.loginWithRefreshToken(clusterDomainWithToken.tokens.refresh_token).subscribe();
100+
}
101+
if (this.exposeApps.NETSUITE) {
102+
this.helperService.setBaseApiURL(AppUrl.NETSUITE);
103+
this.netsuiteAuthService.loginWithRefreshToken(clusterDomainWithToken.tokens.refresh_token).subscribe();
104+
}
105+
if (this.exposeApps.XERO) {
106+
this.helperService.setBaseApiURL(AppUrl.XERO);
107+
this.xeroAuthService.loginWithRefreshToken(clusterDomainWithToken.tokens.refresh_token).subscribe();
108+
}
87109
this.redirect(redirectUri);
88110
} else {
89111
this.redirect(redirectUri);

0 commit comments

Comments
 (0)