11import { Component , Inject , OnInit } from '@angular/core' ;
2- import { NavigationEnd , Router } from '@angular/router' ;
2+ import { NavigationEnd , Router , ActivatedRoute } from '@angular/router' ;
33import { MinimalUser } from 'src/app/core/models/db/user.model' ;
44import { AppName , AppUrl , IntacctOnboardingState } from 'src/app/core/models/enum/enum.model' ;
55import { IntacctWorkspace } from 'src/app/core/models/intacct/db/workspaces.model' ;
@@ -9,6 +9,7 @@ import { WindowService } from 'src/app/core/services/common/window.service';
99import { AppcuesService } from 'src/app/core/services/integration/appcues.service' ;
1010import { UserService } from 'src/app/core/services/misc/user.service' ;
1111import { SiWorkspaceService } from 'src/app/core/services/si/si-core/si-workspace.service' ;
12+ import { SiAuthService } from 'src/app/core/services/si/si-core/si-auth.service' ;
1213
1314@Component ( {
1415 selector : 'app-intacct' ,
@@ -29,10 +30,12 @@ export class IntacctComponent implements OnInit {
2930 private appcuesService : AppcuesService ,
3031 private helperService : HelperService ,
3132 private router : Router ,
33+ private route : ActivatedRoute ,
3234 private storageService : StorageService ,
3335 private userService : UserService ,
3436 private windowService : WindowService ,
35- private workspaceService : SiWorkspaceService
37+ private workspaceService : SiWorkspaceService ,
38+ private siAuthService : SiAuthService
3639 ) {
3740 this . windowReference = this . windowService . nativeWindow ;
3841 }
@@ -77,13 +80,26 @@ export class IntacctComponent implements OnInit {
7780 ) ;
7881 }
7982
83+ private handleAuthParameters ( ) : void {
84+ this . route . queryParams . subscribe ( params => {
85+ const authCode = params . code ;
86+ if ( authCode ) {
87+ this . siAuthService . loginWithAuthCode ( authCode ) . subscribe (
88+ ( ) => this . getOrCreateWorkspace ( )
89+ ) ;
90+ } else {
91+ this . getOrCreateWorkspace ( ) ;
92+ }
93+ } ) ;
94+ }
95+
8096 ngOnInit ( ) : void {
8197 this . router . events . subscribe ( ( event ) => {
8298 if ( event instanceof NavigationEnd ) {
8399 ( window as any ) . Appcues && ( window as any ) . Appcues . page ( ) ;
84100 }
85101 } ) ;
86- this . getOrCreateWorkspace ( ) ;
102+ this . handleAuthParameters ( ) ;
87103 }
88104
89105}
0 commit comments