All files / app/services session.service.ts

100% Statements 12/12
100% Branches 2/2
100% Functions 6/6
100% Lines 11/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35              142x   71x     71x     4812x       46x 46x 46x       4x 4x 4x       50x      
import { Injectable } from '@angular/core';
import { BehaviorSubject, Observable } from 'rxjs';
import { SessionInformation } from '../interfaces/sessionInformation.interface';
 
@Injectable({
  providedIn: 'root'
})
export class SessionService {
 
  public isLogged = false;
  public sessionInformation: SessionInformation | undefined;
 
  private isLoggedSubject = new BehaviorSubject<boolean>(this.isLogged);
 
  public $isLogged(): Observable<boolean> {
    return this.isLoggedSubject.asObservable();
  }
 
  public logIn(user: SessionInformation): void {
    this.sessionInformation = user;
    this.isLogged = true;
    this.next();
  }
 
  public logOut(): void {
    this.sessionInformation = undefined;
    this.isLogged = false;
    this.next();
  }
 
  private next(): void {
    this.isLoggedSubject.next(this.isLogged);
  }
}