@@ -2,17 +2,20 @@ import { HttpClient } from '@angular/common/http';
22import { Injectable } from '@angular/core' ;
33import { GoogleLoginProvider , SocialAuthService } from 'angularx-social-login' ;
44import { CookieService } from 'ngx-cookie-service' ;
5- import { UserEnum } from 'src/environments/enum' ;
5+ import { EnvironmentType , UserEnum } from 'src/environments/enum' ;
66import { environment } from 'src/environments/environment' ;
77import { JwtHelperService } from '@auth0/angular-jwt' ;
88import { map } from 'rxjs/operators' ;
9+ import { of } from 'rxjs' ;
910
1011@Injectable ( {
1112 providedIn : 'root'
1213} )
1314export class LoginService {
1415 baseUrl : string ;
1516 helper : JwtHelperService ;
17+ isLegacyProd : boolean = environment . production === EnvironmentType . TT_PROD_LEGACY ;
18+ localStorageKey = this . isLegacyProd ? 'user2' : 'user' ;
1619
1720 constructor (
1821 private http ?: HttpClient ,
@@ -34,31 +37,56 @@ export class LoginService {
3437 }
3538
3639 isLogin ( ) {
37- const token = this . getLocalStorage ( 'user' ) ;
38- return this . isValidToken ( token ) ;
40+ const token = this . getLocalStorage ( this . localStorageKey ) ;
41+ if ( this . isLegacyProd ) {
42+ const user = JSON . parse ( token ) ;
43+ return user && this . cookieService . check ( 'idtoken' ) ? of ( true ) : of ( false ) ;
44+ } else {
45+ return this . isValidToken ( token ) ;
46+ }
3947 }
4048
4149 getUserId ( ) : string {
42- const token = this . getLocalStorage ( 'user' ) ;
43- const user = this . helper . decodeToken ( token ) ;
50+ const token = this . getLocalStorage ( this . localStorageKey ) ;
51+ let user ;
52+ if ( this . isLegacyProd ) {
53+ user = JSON . parse ( token ) ;
54+ } else {
55+ user = this . helper . decodeToken ( token ) ;
56+ }
4457 return user [ UserEnum . ID ] ;
4558 }
4659
4760 getName ( ) : string {
48- const token = this . getLocalStorage ( 'user' ) ;
49- const user = this . helper . decodeToken ( token ) ;
61+ const token = this . getLocalStorage ( this . localStorageKey ) ;
62+ let user ;
63+ if ( this . isLegacyProd ) {
64+ user = JSON . parse ( token ) ;
65+ } else {
66+ user = this . helper . decodeToken ( token ) ;
67+ }
5068 return user [ UserEnum . NAME ] ;
5169 }
5270
5371 getUserEmail ( ) : string {
54- const token = this . getLocalStorage ( 'user' ) ;
55- const user = this . helper . decodeToken ( token ) ;
72+ const token = this . getLocalStorage ( this . localStorageKey ) ;
73+ let user ;
74+ if ( this . isLegacyProd ) {
75+ user = JSON . parse ( token ) ;
76+ } else {
77+ user = this . helper . decodeToken ( token ) ;
78+ }
5679 return user [ UserEnum . EMAIL ] ;
5780 }
5881
5982 getUserGroup ( ) : string {
60- const token = this . getLocalStorage ( 'user' ) ;
61- const user = this . helper . decodeToken ( token ) ;
83+ const token = this . getLocalStorage ( this . localStorageKey ) ;
84+ let user ;
85+ if ( this . isLegacyProd ) {
86+ user = JSON . parse ( token ) ;
87+ } else {
88+ user = this . helper . decodeToken ( token ) ;
89+ }
6290 return user [ UserEnum . GROUPS ] ;
6391 }
6492
0 commit comments