All files / app/services session.service.ts

100% Statements 15/15
100% Branches 0/0
100% Functions 4/4
100% Lines 13/13

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 357x 7x           7x   7x     7x     10x       3x 3x 3x       2x 2x 2x       5x      
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);
  }
}