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

How to get true/false from NbAuthService.isAuthenticated() #15

Closed
nnixaa opened this issue Sep 29, 2017 · 4 comments
Closed

How to get true/false from NbAuthService.isAuthenticated() #15

nnixaa opened this issue Sep 29, 2017 · 4 comments
Assignees

Comments

@nnixaa
Copy link
Collaborator

nnixaa commented Sep 29, 2017

by: @dzungdev
moved from: akveo/ngx-admin#1298

Hi all,
I would like to ask how I can get true/false from NbAuthService.isAuthenticated()? The problem now is it always returns the Observable so my if() is always true even I haven't logged-in yet (suppose false if haven't logged-in yet)

if (this.nbAuthService.isAuthenticated()) { console.log('run here2'); return true; }
Best regards

@nnixaa
Copy link
Collaborator Author

nnixaa commented Sep 29, 2017

@dzungdev as this is observable, you need to subscribe to it and move your if statement into the subscribe callback:

this.nbAuthService.isAuthenticated().subscribe((result) => {
  if (result) { ... }
})

Please note, isAuthenticated is executed only one time on subscribe, if you need to listen to the token change, consider using onAuthenticationChange.

@dzungdev
Copy link

dzungdev commented Sep 29, 2017

Hi @nnixaa , thank you very much for your helping.

@gael-ft
Copy link

gael-ft commented Oct 3, 2017

Hey @nnixaa isAuthenticated() is never returning true or false.
It return the token value (a string for example) or null.
It comes from token && token.getValue() which not produce a boolean but the right part if the first is not null.

Is it the normal behavior ?

@nnixaa
Copy link
Collaborator Author

nnixaa commented Oct 4, 2017

Hey @gael-ft, yep you right, this is clearly a bug, we'll fix it soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants