import { Component, OnInit } from '@angular/core' import { AuthService } from '../services/auth.service' @Component({ selector: 'app-admin', templateUrl: './admin.component.html', styleUrls: ['./admin.component.scss'] }) export class AdminComponent implements OnInit { public authCheck: boolean = false public userName: string = '' public password: string = '' constructor(private authService: AuthService) { } ngOnInit(): void { const body = { token: window.sessionStorage.getItem('authToken') } this.authService.authCheck(body).toPromise().then((response) => { this.authCheck = response.status == 200 },(error) => { console.error('Auth ERROR', error) }).catch((e) => { console.error('Auth CATCH', e) }) } login(): void { const body = { usr: this.userName, pwd: this.password } this.authService.login(body).toPromise().then((response) => { this.authCheck = response.status == 200 if(this.authCheck) { window.sessionStorage.setItem('authToken', response.authToken) } },(error) => { console.error('Auth ERROR', error) }).catch((e) => { console.error('Auth CATCH', e) }) } }