frontend-smartfarming/agrilink_vocpro/src/app/pages/dashboard/layouts/sidebar/sidebar.component.ts

33 lines
931 B
TypeScript
Raw Normal View History

2024-09-17 06:50:34 +00:00
import { Component } from '@angular/core';
import { AuthService } from '../../../../cores/services/auth.service';
import { Router } from '@angular/router';
import { ToastrService } from 'ngx-toastr';
2024-09-17 06:50:34 +00:00
@Component({
selector: 'app-sidebar',
standalone: true,
templateUrl: './sidebar.component.html',
styleUrls: ['./sidebar.component.scss']
2024-09-17 06:50:34 +00:00
})
export class SidebarComponent {
fullName: string | null = null;
avatar: string | null = null;
2024-09-17 06:50:34 +00:00
constructor(private authService: AuthService, private router: Router, private toast: ToastrService) {
this.fullName = this.authService.getUserFullName();
this.avatar = this.authService.getAvatar();
}
onLogout(): void {
this.authService.logout().subscribe(
() => {
this.router.navigate(['/auth']);
this.toast.success('Logout successful');
},
(error: any) => {
this.toast.error(error.error.message);
}
);
}
2024-09-17 06:50:34 +00:00
}