I am creating a guard for Angular 6 and I have encountered the problem that operators rxjs
no longer go as before. Aside from being imperatively different, I had to put the .map
or .task
within a .pipe()
. This has allowed me to solve the problems. However, I do not see how to replace or import the operator .do
.
I show you my code and see if you can help me find an alternative. The error that VSC gives me is:
"The module '" c: / Users / upload / Desktop / We rotate CPanel / node_modules / rxjs / operators / index "' does not have any member 'do' exported." and "The property 'do' does not exist in the 'Observable' type.".
import { Injectable } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Router } from '@angular/router';
import { Observable } from 'rxjs';
import { AuthService } from '../services/auth.service';
import { map, take, do } from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
export class AuthGuard implements CanActivate {
constructor (
private router: Router,
private authService: AuthService
) {}
canActivate(
next: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean {
return this.authService.afAuth.authState.pipe(
take(1)).pipe(
map(authState => !! authState)).do(logado => {
if (!logado) {
this.router.navigate(['/login']);
}
});
}
}