@@ -3,7 +3,7 @@ import { AzureAdB2CService } from './services/azure.ad.b2c.service';
33import { Router } from '@angular/router' ;
44import { FeatureToggleCookiesService } from '../shared/feature-toggles/feature-toggle-cookies/feature-toggle-cookies.service' ;
55
6- import { environment , CLIENT_URL , AUTH_URL } from 'src/environments/environment' ;
6+ import { environment , CLIENT_URL } from 'src/environments/environment' ;
77import { EnvironmentType } from 'src/environments/enum' ;
88import { LoginService } from './services/login.service' ;
99import { UserService } from '../user/services/user.service' ;
@@ -22,7 +22,7 @@ declare global {
2222export class LoginComponent implements OnInit {
2323 isProduction = environment . production === EnvironmentType . TT_PROD_LEGACY ;
2424 cliendId = CLIENT_URL ;
25- authUrl = AUTH_URL ;
25+ authUrl = environment . authUrl ;
2626 auth2 : any ;
2727
2828
@@ -35,65 +35,16 @@ export class LoginComponent implements OnInit {
3535 private ngZone ?: NgZone
3636 ) { }
3737
38-
39- googleAuthSDK ( ) {
40- const sdkLoaded = 'googleSDKLoaded' ;
41- const gapi = 'gapi' ;
42-
43- ( window as any ) [ sdkLoaded ] = ( ) => {
44- ( window as any ) [ gapi ] . load ( 'auth2' , ( ) => {
45- this . auth2 = ( window as any ) [ gapi ] . auth2 . init ( {
46- client_id : this . cliendId ,
47- plugin_name : 'login' ,
48- cookiepolicy : 'single_host_origin' ,
49- scope : 'profile email'
50- } ) ;
51- } ) ;
52- } ;
53-
54- ( async ( d , s , id ) => {
55- const keyGoogle = 'src' ;
56- const gjs = d . getElementsByTagName ( s ) [ 1 ] ;
57- let js = gjs ;
58- if ( d . getElementById ( id ) ) { return ; }
59- js = d . createElement ( s ) ; js . id = id ;
60- js [ keyGoogle ] = 'https://accounts.google.com/gsi/client' ;
61- gjs . parentNode . insertBefore ( js , gjs ) ;
62- } ) ( document , 'script' , 'async defer' ) ;
63- }
64-
6538 ngOnInit ( ) {
66-
67- this . googleAuthSDK ( ) ;
68- if ( this . isProduction && this . azureAdB2CService . isLogin ( ) ) {
69- this . router . navigate ( [ '' ] ) ;
70- } else {
71- this . loginService . isLogin ( ) . subscribe ( isLogin => {
72- if ( isLogin ) {
73- this . router . navigate ( [ '' ] ) ;
74- }
39+ if ( ! this . isProduction ) {
40+ this . loginService . getUser ( null ) . subscribe ( ( resp ) => {
41+ this . loginService . setCookies ( ) ;
42+ const tokenObject = JSON . stringify ( resp ) ;
43+ const tokenJson = JSON . parse ( tokenObject ) ;
44+ this . loginService . setLocalStorage ( 'user' , tokenJson . token ) ;
45+ this . ngZone . run ( ( ) => this . router . navigate ( [ '' ] ) ) ;
7546 } ) ;
7647 }
77- window . handleCredentialResponse = ( response ) => {
78- const { credential = '' } = response ;
79- this . featureToggleCookiesService . setCookies ( ) ;
80- this . loginService . setLocalStorage ( 'idToken' , credential ) ;
81- this . loginService . getUser ( credential ) . subscribe ( ( resp ) => {
82- this . loginService . setCookies ( ) ;
83- const tokenObject = JSON . stringify ( resp ) ;
84- const tokenJson = JSON . parse ( tokenObject ) ;
85- this . loginService . setLocalStorage ( 'user' , tokenJson . token ) ;
86- this . ngZone . run ( ( ) => this . router . navigate ( [ '' ] ) ) ;
87- } ) ;
88- } ;
89- this . loginService . getUser ( 'test' ) . subscribe ( ( resp ) => {
90- this . loginService . setCookies ( ) ;
91- const tokenObject = JSON . stringify ( resp ) ;
92- console . log ( tokenObject )
93- const tokenJson = JSON . parse ( tokenObject ) ;
94- this . loginService . setLocalStorage ( 'user' , tokenJson . token ) ;
95- this . ngZone . run ( ( ) => this . router . navigate ( [ '' ] ) ) ;
96- } ) ;
9748 }
9849
9950 login ( ) : void {
@@ -116,7 +67,7 @@ export class LoginComponent implements OnInit {
11667 }
11768
11869 loginAuth ( ) : string {
119- return this . authUrl ;
70+ return ` ${ this . authUrl } /authn/login/timeTracker` ;
12071 }
12172
12273}
0 commit comments