@@ -2,11 +2,12 @@ import { Component, HostBinding, OnInit } from "@angular/core";
22declare var $ : any ;
33
44import { SettingsService } from "./core/settings/settings.service" ;
5- import { OAuthService , JwksValidationHandler } from "angular-oauth2-oidc" ;
6- import { Router } from "@angular/router" ;
7- import { authConfig } from "./core/auth/auth.config" ;
8- import { environment } from "../environments/environment" ;
9- import { tap } from "rxjs/operators" ;
5+ // import { authConfig } from "./core/auth/auth.config";
6+ import { AuthService } from "@core/auth/auth.service" ;
7+ import { Observable } from "rxjs" ;
8+
9+
10+
1011
1112@Component ( {
1213 selector : "app-root" ,
@@ -26,31 +27,22 @@ export class AppComponent implements OnInit {
2627 @HostBinding ( "class.aside-toggled" ) get asideToggled ( ) { return this . settings . layout . asideToggled ; }
2728 @HostBinding ( "class.aside-collapsed-text" ) get isCollapsedText ( ) { return this . settings . layout . isCollapsedText ; }
2829
29- constructor ( private router : Router ,
30- private oauthService : OAuthService ,
31- public settings : SettingsService ) {
32- this . configureWithNewConfigApi ( ) ;
33- }
30+ isAuthenticated : Observable < boolean > ;
31+ isDoneLoading : Observable < boolean > ;
32+ canActivateProtectedRoutes : Observable < boolean > ;
33+
34+ constructor (
35+ private authService : AuthService ,
36+ public settings : SettingsService
37+ ) {
38+ this . isAuthenticated = this . authService . isAuthenticated$ ;
39+ this . isDoneLoading = this . authService . isDoneLoading$ ;
40+ this . canActivateProtectedRoutes = this . authService . canActivateProtectedRoutes$ ;
3441
35- private async configureWithNewConfigApi ( ) {
36- this . oauthService . configure ( authConfig ) ;
37- this . oauthService . setStorage ( localStorage ) ;
38- this . oauthService . tokenValidationHandler = new JwksValidationHandler ( ) ;
39-
40-
41- this . settings . loadDiscoveryDocumentAndTryLogin ( ) . pipe ( tap ( doc => {
42- if ( ! environment . production )
43- console . log ( doc ) ;
44- } ) ) . subscribe ( a => {
45- this . oauthService . setupAutomaticSilentRefresh ( ) ;
46- } ) ;
47- // this.oauthService.loadDiscoveryDocument().then(doc => {
48- // if (!environment.production)
49- // console.log(doc);
50- // this.oauthService.tryLogin();
51- // });
42+ this . authService . runInitialLoginSequence ( ) ;
5243 }
5344
45+
5446 ngOnInit ( ) {
5547 $ ( document ) . on ( "click" , "[href=\"#\"]" , e => e . preventDefault ( ) ) ;
5648 }
0 commit comments