import { Inject, Injectable } from '@angular/core'; import { CFG } from '../const'; import { OAuthService } from 'angular-oauth2-oidc'; @Injectable({ providedIn: 'root' }) export class AuthService { constructor( @Inject(CFG) private readonly cfg: any, private readonly auth: OAuthService ) { } get isLogged(): boolean { return this.auth.hasValidAccessToken(); } async login() { this.auth.configure(this.cfg.auth); const token = await this.auth.loadDiscoveryDocumentAndLogin().then(() => this.auth.getAccessToken()); } logout(): void { this.auth.logOut(); } }