import { AfterViewInit , Component , ElementRef , EventEmitter , OnDestroy , OnInit , Output } from '@angular/core' ; import { DvService , DvServiceFactory } from '@deja-vu/core' ; @ Component ( { selector : 'authentication-logged-in' , templateUrl : './logged-in.component.html' } ) export class LoggedInComponent implements AfterViewInit , OnInit , OnDestroy { @ Output ( ) user = new EventEmitter ( ) ; private dvs : DvService ; constructor ( private readonly elem , private readonly dvf ) { } ngOnInit ( ) { this . dvs = this . dvf . forComponent ( this ) . withRefreshCallback ( ( ) => { this . dvs . eval ( ) ; } ) . build ( ) ; } ngAfterViewInit ( ) { setTimeout ( ( ) => { this . dvs . eval ( ) ; } ) ; } async dvOnEval ( ) { const user = this . dvs . getItem ( 'user' ) ; if ( user ) { this . user . emit ( user ) ; } else { this . user . emit ( null ) ; throw new Error ( 'No user is logged in' ) ; } } ngOnDestroy ( ) { this . dvs . onDestroy ( ) ; } }