I want to craete angular route guard in my app. I found this code but don't understand why we map user
to !!user
. What's the purpose of map(user => !!user)
line?
canActivate(
next: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean> {
return this.auth.user.pipe()
take(1),
map(user => !!user),
tap(loggedIn => {
if (!loggedIn) {
console.log('access denied')
this.router.navigate(['/login']);
}
})
)