Comments (15)
Hey! Are you trying to specify another token name for tokenNotExpired
to use? If, so you can pass the name of your token in when calling it.
@CanActivate(() => tokenNotExpired('my_token_name'))
Let me know if that's what you're looking for :)
from angular2-jwt.
Hi,
Thanks for the fast reply!
That's what I am trying to achieve but I was wondering if it was possible to do it without specifying the name in the function. Just to keep it DRY.
I tried to create an AuthVerificationService that would look like the following :
import {Injectable} from 'angular2/core';
import {AuthConfig, tokenNotExpired} from 'angular2-jwt';
@Injectable()
export class AuthVerificationService {
constructor(private authConfig:AuthConfig) { }
tokenVerified():boolean {
var token = this.authConfig.tokenGetter();
return tokenNotExpired(null, token);
}
}
and have it injected in my "private" components, but I don't know how to do the following part :
import {Component} from 'angular2/core';
import {CanActivate} from 'angular2/router';
import {AuthVerificationService} from '../services/auth-verification.service';
@Component( ... )
@CanActivate(() => AuthVerificationService.tokenVerified()) // Error, "static" method not good...
export class DashboardComponent { }
I might as well just keep the default name and getter...
If you have any idea to do it though I'll be happy to read about it =D
Thanks again.
Cheers!
from angular2-jwt.
This is actually probably something that tokenNotExpired
should be getting from AuthConfig
when the app is bootstrapped, but it isn't currently set up for that. I'll put in a fix for the next release.
from angular2-jwt.
Need PR?
from angular2-jwt.
Until this is integrated it would be great if it was mentioned in the docs. I spent a couple hours trying to figure out why tokenNotExpired
returned false and jwtHelper.isTokenExpired
also returned false, when using an AuthConfig
defining another name for the tokenName
from angular2-jwt.
@RicardoRFaria feel free to submit a PR if you like :)
@h0st1le good call--I'll add that, thanks.
from angular2-jwt.
any progress on this?
from angular2-jwt.
Hello, any updates on this?
from angular2-jwt.
Hello, help anyone!
tokenNotExpired is not working properly!
While login it matches username and password from database and also it generated token but after login page doesn't redirect to profile page. I had uploaded to cloud9.
But in localhost work fine.
tokenNotExpired return false
from angular2-jwt.
@denishp83 Here also the same!
@chenkie After successful login, tokenNotExpired always returns false. So it doesn't redirect the secured page.
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!
from angular2-jwt.
@kksrini89 have you double checked that the correct token is used by tokenNotExpired
?
from angular2-jwt.
@chenkie Yes I did. But it showed me tokenNotExpired is not defined even though I have given reference using import { tokenNotExpired } from 'angular2-jwt';
from angular2-jwt.
Ok if it's not defined then that's likely another problem. Probably best to open a separate issue for it.
from angular2-jwt.
sure. Let me create a new ticket for this! thanks @chenkie
from angular2-jwt.
@chenkie created new ticket #369
from angular2-jwt.
Related Issues (20)
- tokenGetter using async documentation not complete
- Error: The inspected token doesn't appear to be a JWT. Check to make sure it has three parts and see https://jwt.io for more. HOT 1
- Angular 12 support HttpInterceptor Context HOT 4
- Angular 13 support HOT 28
- upstream dependency conflict while installing angular2-jwt package using angular-cli HOT 1
- ``
- v5.1.0 broke azure devops publishing HOT 5
- Please respect semver HOT 3
- tokenGetter does not support Promise HOT 2
- Getting an issue of no exported member from angular core HOT 1
- Encourage the library authors to publish an Ivy distribution HOT 2
- Release v5.1.1 decodeToken<T = any>(token?: string): T | Promise<T> HOT 4
- 'ɵɵngDeclareFactory' (imported as 'i0') was not found in '@angular/core' HOT 2
- Authorization header stops going through after the browser sits idle for a while. HOT 7
- JwtInterceptor not work HOT 2
- No header with standalone components HOT 4
- Angular 16 support HOT 1
- Package not working with es2022 HOT 4
- Angular JWT 5.0.2 not compiling with Angular 13.3.6 HOT 1
- App no longer working after installing auth0 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angular2-jwt.