Using Angular with AngularFire2 (Firebase package) and am trying to use a guard to prevent all users except one from accessing a specific route. But the code below won't work. I get the error:
Class 'AuthGuard' incorrectly implements interface 'CanActivate'. Type 'void' is not assignable to type 'boolean | Observable | Promise'.
import { Injectable } from '@angular/core';
import { CanActivate } from '@angular/router';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/of';
import { AngularFire, FirebaseListObservable } from 'angularfire2';
@Injectable()
export class AuthGuard implements CanActivate {
constructor(private af: AngularFire) { }
canActivate() {
this.af.auth.subscribe(auth => {
if (auth.uid === 'xyz123') {
return Observable.of(true);
} else {
return Observable.of(false);
}
})
}
}
true
andfalse
(without anObservable
) – Günter Zöchbauersubscribe
at all – Günter Zöchbauer