Giter Club home page Giter Club logo

Comments (15)

chenkie avatar chenkie commented on May 21, 2024

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.

 avatar commented on May 21, 2024

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.

chenkie avatar chenkie commented on May 21, 2024

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.

RicardoRFaria avatar RicardoRFaria commented on May 21, 2024

Need PR?

from angular2-jwt.

h0st1le avatar h0st1le commented on May 21, 2024

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.

chenkie avatar chenkie commented on May 21, 2024

@RicardoRFaria feel free to submit a PR if you like :)

@h0st1le good call--I'll add that, thanks.

from angular2-jwt.

v3rron avatar v3rron commented on May 21, 2024

any progress on this?

from angular2-jwt.

siarheipashkevich avatar siarheipashkevich commented on May 21, 2024

Hello, any updates on this?

from angular2-jwt.

 avatar commented on May 21, 2024

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.

kksrini89 avatar kksrini89 commented on May 21, 2024

@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.

chenkie avatar chenkie commented on May 21, 2024

@kksrini89 have you double checked that the correct token is used by tokenNotExpired?

from angular2-jwt.

kksrini89 avatar kksrini89 commented on May 21, 2024

@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.

chenkie avatar chenkie commented on May 21, 2024

Ok if it's not defined then that's likely another problem. Probably best to open a separate issue for it.

from angular2-jwt.

kksrini89 avatar kksrini89 commented on May 21, 2024

sure. Let me create a new ticket for this! thanks @chenkie

from angular2-jwt.

kksrini89 avatar kksrini89 commented on May 21, 2024

@chenkie created new ticket #369

from angular2-jwt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.