@@ -17,10 +17,14 @@ export class AuthService {
17
17
18
18
constructor ( private _adal : Adal5Service ) {
19
19
this . _adal . init ( this . _config ) ;
20
+
21
+ if ( this . isLoggedIn ( ) ) {
22
+ console . log ( `Rechargement de la page, c'est le meme token et il expire dans ${ this . _expireIn ( ) } secondes` ) ;
23
+ }
20
24
}
21
25
22
26
public isLoggedIn ( ) : boolean {
23
- return this . _adal . userInfo . authenticated ;
27
+ return this . _adal . userInfo && this . _adal . userInfo . authenticated ;
24
28
}
25
29
26
30
public signOut ( ) : void {
@@ -32,7 +36,7 @@ export class AuthService {
32
36
}
33
37
34
38
public getName ( ) : string {
35
- return this . _user . profile . name ;
39
+ return this . _adal . userInfo . profile . name ;
36
40
}
37
41
38
42
public getToken ( ) : string {
@@ -41,10 +45,10 @@ export class AuthService {
41
45
42
46
public completeAuthentication ( ) : void {
43
47
this . _adal . handleWindowCallback ( ) ;
44
- this . _adal . getUser ( ) . subscribe ( user => {
45
- this . _user = user ;
46
- console . log ( this . _adal . userInfo ) ;
47
- var expireIn = user . profile . exp - new Date ( ) . getTime ( ) ;
48
- } ) ;
48
+ console . log ( `Authentification OK et le token expire dans ${ this . _expireIn ( ) } secondes` ) ;
49
+ }
50
+
51
+ private _expireIn ( ) : number {
52
+ return Math . round ( this . _adal . userInfo . profile . exp - new Date ( ) . getTime ( ) / 1000 ) ;
49
53
}
50
54
}
0 commit comments