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

tokenNotExpired() is not defined #369

Closed
kksrini89 opened this issue Jun 20, 2017 · 4 comments
Closed

tokenNotExpired() is not defined #369

kksrini89 opened this issue Jun 20, 2017 · 4 comments

Comments

@kksrini89
Copy link

After successful login, tokenNotExpired always returns false. So it doesn't redirect the secured page with angular guard.

But it showed me tokenNotExpired is not defined even though I have given reference using
import { tokenNotExpired } from 'angular2-jwt';

Any Idea pls?

NOTE: I manually passed stored localstorage token name to tokenNotExpired method. It resolves the problem but I don't think this is the right way!

public isAuthenticated() : boolean{
   return tokenNotExpired('id_token');
}
@chenkie
Copy link
Contributor

chenkie commented Jun 20, 2017

I'm a bit confused by your mention of tokenNotExpired not being defined. Are you able to access the function in your app?

Under the hood, tokenNotExpired is looking for a token called 'token'. You can set your default token name to be id_token in your configuration if you like.

export function authHttpServiceFactory(http: Http, options: RequestOptions) {
  return new AuthHttp(new AuthConfig({
    tokenName: 'id_token'
  }), http, options);
}

@kksrini89
Copy link
Author

@chenkie My problem solved by replacing the token. But anyhow I wondering why AUTH_PROVIDERS are not working from "angular-jwt" whereas we use exported function to resolve this problem.

@chenkie
Copy link
Contributor

chenkie commented Jun 20, 2017

It has to do with functions being statically analyzable when the app is booted up. You can try using the AuthModule in your imports but there may be issues. Things will be fixed up for a v1.0 release.

@kksrini89
Copy link
Author

Thank you for your quick help!

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