forked from CodeURJC-DAW-2023-24/webapp07
-
Notifications
You must be signed in to change notification settings - Fork 0
/
header.component.ts
54 lines (49 loc) · 1.35 KB
/
header.component.ts
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { Component } from '@angular/core';
import { AuthService } from '../services/auth.service';
import { Router } from '@angular/router';
import { UserService } from '../services/user.service';
@Component({
selector: 'header',
templateUrl: './header.component.html',
styleUrl: './header.component.css'
})
export class HeaderComponent {
isLoggedIn;
userPhoto:string = "";
constructor(private authService: AuthService, private router: Router, private userService: UserService) {
this.isLoggedIn = this.authService.getIsLoggedIn();
}
logout(): void {
this.authService.logout().subscribe({
next: () => {
this.authService.setIsLoggedIn(false);
window.location.reload();
this.router.navigate(['inner-page']);
},
error: (error: any) => {
console.error('Log out failure', error);
window.location.reload();
this.router.navigate(['errorPage']);
}
});
}
ngOnInit(): void {
if (this.isLoggedIn) {
this.authService.getUserId().subscribe({
next: (data: any) => {
this.userService.getUserPhoto(data).subscribe({
next: (data: any) => {
this.userPhoto = data;
},
error: (error: any) => {
console.error('User photo retrieval failure', error);
}
});
},
error: (error: any) => {
console.error('User id retrieval failure', error);
}
});
}
}
}