Revize 2c5da396
Přidáno uživatelem Jakub Hlaváč před téměř 4 roky(ů)
src/app/shared/nav-bar/components/nav-bar.component.ts | ||
---|---|---|
1 |
import {Component, OnInit} from '@angular/core'; |
|
1 |
import {Component, OnDestroy, OnInit} from '@angular/core';
|
|
2 | 2 |
import {AuthService} from '../../../auth/services/auth.service'; |
3 |
import {Router} from '@angular/router';
|
|
4 |
import {UserState} from '../../../auth/states/user.state';
|
|
3 |
import {User} from '../../../auth/models/user';
|
|
4 |
import {Subscription} from 'rxjs';
|
|
5 | 5 |
|
6 | 6 |
@Component({ |
7 | 7 |
selector: 'app-nav-bar', |
8 | 8 |
templateUrl: './nav-bar.component.html', |
9 | 9 |
styleUrls: ['./nav-bar.component.scss'] |
10 | 10 |
}) |
11 |
export class NavBarComponent implements OnInit { |
|
11 |
export class NavBarComponent implements OnInit, OnDestroy {
|
|
12 | 12 |
|
13 |
loggedUser: User; |
|
14 |
subscription: Subscription[] = []; |
|
13 | 15 |
constructor( |
14 |
private authService: AuthService, |
|
15 |
private router: Router, |
|
16 |
private userState: UserState |
|
16 |
private authService: AuthService |
|
17 | 17 |
) { |
18 | 18 |
} |
19 | 19 |
|
20 | 20 |
ngOnInit(): void { |
21 |
this.setUser(); |
|
22 |
} |
|
23 |
|
|
24 |
setUser(){ |
|
25 |
this.authService.getUserState().subscribe(res => { |
|
26 |
if(res){ |
|
27 |
this.loggedUser = res; |
|
28 |
} |
|
29 |
}); |
|
21 | 30 |
} |
22 | 31 |
|
23 | 32 |
logOut(): void { |
24 |
this.userState.setLoggedIn(false); |
|
25 | 33 |
this.authService.doLogout(); |
26 | 34 |
} |
35 |
|
|
36 |
ngOnDestroy(): void { |
|
37 |
this.subscription.forEach(subs => subs.unsubscribe()); |
|
38 |
} |
|
27 | 39 |
} |
Také k dispozici: Unified diff
Re #8469 - Improvment security - implementace
+ usage of localStorage for fields
+ loading properties form cookies to state