I have a user settings page that only the owner should have access to. I want to use CanActivate to implement the restriction. CanActivate requires the output to be boolean or the observable of a boolean. However, my code outputs an observable of an observable of a boolean.
Type 'Observable<Observable<boolean>>' is not assignable to type 'boolean | Observable<boolean> | Promise<boolean>'.
Here my code
@Injectable()
export class UserGuard implements CanActivate {
constructor(
private route: ActivatedRoute,
private userService: UserService
) { }
canActivate() {
const username = this.route.snapshot.paramMap.get('username');
return this.userService.authState().map(auth => {
return this.userService.getByUid(auth.uid).map(user => {
return user.username === username ? true : false;
});
});
}
}