46
src/app/views/dashboard/dashboard.component.ts
Normal file
46
src/app/views/dashboard/dashboard.component.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import {Component, OnInit} from '@angular/core';
|
||||
import {UserData} from "../../interface/user";
|
||||
import {AuthService} from "../../services/auth.service";
|
||||
import {ApiService} from "../../services/api.service";
|
||||
import {NgbDatepicker, NgbDateStruct} from "@ng-bootstrap/ng-bootstrap";
|
||||
import {FormsModule} from "@angular/forms";
|
||||
import {NgIf} from "@angular/common";
|
||||
import {Router} from "@angular/router";
|
||||
|
||||
@Component({
|
||||
selector: 'app-dashboard',
|
||||
standalone: true,
|
||||
imports: [
|
||||
NgbDatepicker,
|
||||
FormsModule,
|
||||
NgIf
|
||||
],
|
||||
templateUrl: './dashboard.component.html',
|
||||
styleUrl: './dashboard.component.scss'
|
||||
})
|
||||
export class DashboardComponent implements OnInit {
|
||||
|
||||
isLoggedIn = false;
|
||||
|
||||
userData: UserData = {
|
||||
uuid: null,
|
||||
username: null,
|
||||
email: null,
|
||||
createdAt: null
|
||||
}
|
||||
|
||||
constructor(private authService: AuthService, private apiService: ApiService, private router: Router) {
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
if (this.authService.isLoggedIn()) {
|
||||
this.apiService.getCurrentUser().subscribe(res => {
|
||||
this.userData = res;
|
||||
this.isLoggedIn = true;
|
||||
})
|
||||
} else {
|
||||
this.router.navigate(['/login']).then();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user