ВК
Size: a a a
ВК
ОС
<ng-container *ngComponentOutlet="(component | async)!"></ng-container>ТЖ
ВК
7
ON
_login(credentials: IAuthCredentials): Observable<any> {
return this.authService.auth$(credentials)
.pipe(
map((token: IAuthContext) => this._success(token)),
catchError(error => {
return of(false)
})
);
}
private _success(token: IAuthContext): Observable<any> {
this.router.navigate(['/']);
return of(false);
}canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> {
return this.auth.isAuth$().pipe(
map((token: boolean) => {
if (!token) {
this.router.navigate(['/login'/login']);
return false;
}
return true})
);
}auth$(credentials: IAuthCredentials): Observable<IAuthContext> {
return this.api.request(Method.POST, 'auth', { body: credentials }).pipe(
map((response: IAuthContext) => this.setCredentials(response)),
);
}
private setCredentials(response: IAuthContext): IAuthContext {
if (response.token) {
localStorage.setItem(ACCESS_TOKEN_LOCAL_STORAGE_KEY, response.token);
} else {
localStorage.removeItem(ACCESS_TOKEN_LOCAL_STORAGE_KEY);
}
this.stateSubject$.next(response);
return response;
}ON
AV
MK
MK
P
Д
OS
Д
SS
fi
С
P
