@@ -2,11 +2,15 @@ import {Component, OnInit} from '@angular/core';
22import { DomSanitizer } from '@angular/platform-browser' ;
33import { Router } from '@angular/router' ;
44import { NgxSpinnerService } from 'ngx-spinner' ;
5- import { Observable } from " rxjs" ;
5+ import { Observable } from ' rxjs' ;
66import { AuthServerProvider } from '../../../../core/auth/auth-jwt.service' ;
7- import { UtmToastService } from '../../../alert/utm-toast.service' ;
87import { ThemeChangeBehavior } from '../../../behaviors/theme-change.behavior' ;
98import { TfaMethod } from '../../../services/tfa/tfa.service' ;
9+ import { extractQueryParamsForNavigation } from "../../../util/query-params-to-filter.util" ;
10+ import { ADMIN_DEFAULT_EMAIL , ADMIN_ROLE } from "../../../constants/global.constant" ;
11+ import { StateStorageService } from "../../../../core/auth/state-storage.service" ;
12+ import { AccountService } from "../../../../core/auth/account.service" ;
13+ import { UtmToastService } from "../../../alert/utm-toast.service" ;
1014
1115
1216@Component ( {
@@ -31,7 +35,10 @@ export class TotpComponent implements OnInit {
3135 private router : Router ,
3236 private spinner : NgxSpinnerService ,
3337 private themeChangeBehavior : ThemeChangeBehavior ,
34- public sanitizer : DomSanitizer ) {
38+ public sanitizer : DomSanitizer ,
39+ private stateStorageService : StateStorageService ,
40+ private accountService : AccountService ,
41+ private utmToast : UtmToastService ) {
3542 }
3643
3744 ngOnInit ( ) : void {
@@ -46,13 +53,10 @@ export class TotpComponent implements OnInit {
4653 . verifyCode ( this . verificationCode ) . subscribe ( ( auth ) => {
4754 if ( auth ) {
4855 this . isVerified = true ;
49- this . spinner . show ( ) ;
50- this . router . navigate ( [ '/dashboard/overview' ] )
51- . then ( ( ) => this . spinner . hide ( ) ) ;
56+ this . startNavigation ( ) ;
5257 }
5358 } , error => {
5459 this . errorMessage = error . headers . get ( 'X-UtmStack-error' ) ;
55- console . log ( error . headers . get ( 'X-UtmStack-error' ) ) ;
5660 this . isVerifying = false ;
5761 } ) ;
5862 }
@@ -66,9 +70,28 @@ export class TotpComponent implements OnInit {
6670 }
6771
6872 clearError ( ) {
69- if ( this . verificationCode . length == 6 ) {
70- this . onSubmit ( )
73+ if ( this . verificationCode . length === 6 ) {
74+ this . onSubmit ( ) ;
7175 }
7276 this . errorMessage = '' ;
7377 }
78+
79+ startNavigation ( ) {
80+ this . accountService . identity ( true ) . then ( account => {
81+ if ( account ) {
82+ const { path, queryParams } =
83+ extractQueryParamsForNavigation ( this . stateStorageService . getUrl ( ) ? this . stateStorageService . getUrl ( ) : '' ) ;
84+ if ( path ) {
85+ this . stateStorageService . resetPreviousUrl ( ) ;
86+ }
87+ const redirectTo = ( account . authorities . includes ( ADMIN_ROLE ) && account . email === ADMIN_DEFAULT_EMAIL )
88+ ? '/getting-started' : ! ! path ? path : '/dashboard/overview' ;
89+ console . log ( redirectTo ) ;
90+ this . router . navigate ( [ redirectTo ] , { queryParams} )
91+ . then ( ( ) => this . spinner . hide ( ) ) ;
92+ } else {
93+ this . utmToast . showError ( 'Login error' , 'User without privileges.' ) ;
94+ }
95+ } ) ;
96+ }
7497}
0 commit comments