Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nbAuthService.onAuthenticationChange always true even not logged-in yet #1300

Closed
dzungdev opened this issue Oct 1, 2017 · 1 comment
Closed

Comments

@dzungdev
Copy link

dzungdev commented Oct 1, 2017

Hi @nnixaa , I already change to onAuthenticationChange in my AuthGuard like below code to return the Observable but it always go to true even I haven't logged-in. Could you please give me the hint for this login problem?

import { Observable } from 'rxjs/Observable';
import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '';
import { Injectable } from '';
import { NbAuthService, NbTokenService } from '';

@Injectable()
export class CanActivateAuthGuard implements CanActivate {

constructor(private router: Router, private nbAuthService: NbAuthService,
private tokenService: NbTokenService) {}

canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {

return this.nbAuthService.onAuthenticationChange().map(
result => {
console.log("logged-in with result", result);
if (result) return true;
}
).catch(() => {
this.router.navigate(['/auth/login']);
console.log("not yet logged-in")
return Observable.of(false);
});
}

}

Best regards

@nnixaa
Copy link
Collaborator

nnixaa commented Oct 10, 2017

Duplicate of akveo/nebular#15

@nnixaa nnixaa marked this as a duplicate of akveo/nebular#15 Oct 10, 2017
@nnixaa nnixaa closed this as completed Oct 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants