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

Restore pre 5.1.1 behavior and fix types #759

Merged
merged 6 commits into from
Dec 20, 2022
Merged

Conversation

frederikprijck
Copy link
Member

@frederikprijck frederikprijck commented Dec 20, 2022

Changes

Release v5.1.1 changed the code in such a way that calling decodeToken('') would call the tokenGetter, while previously it would return null.

Same for isTokenExpired(''), which used to return false, while in 5.1.1 it invokes the tokenGetter. And getTokenExpirationDate, which used to return null, is also calling the tokenGetter in 5.1.1.

The PR reverts that behavior to restore it to the behavior it had pre-5.1.1.

On top of that, this PR is also fixing the types to ensure the following types are correct:

interface Foo { }

var svc = new JwtHelperService();

var token1: null | Foo | Promise<Foo | null> = svc.decodeToken<Foo>();
var token2: null | Foo = svc.decodeToken<Foo>('gdfgdf');
var token2: null | Foo = svc.decodeToken<Foo>('');
var token3: Promise<Foo | null> = svc.decodeToken<Foo>(Promise.resolve(''));

var exp1: Boolean | Promise<Boolean> = svc.isTokenExpired();
var exp2: Boolean = svc.isTokenExpired('');
var exp3: Promise<Boolean> = svc.isTokenExpired(Promise.resolve(''));
var exp4: Boolean = svc.isTokenExpired(null, 10);
var exp4: Boolean | Promise<Boolean> = svc.isTokenExpired(undefined, 10);

var expD1: null | Date | Promise<null | Date> = svc.getTokenExpirationDate();
var expD2: null | Date = svc.getTokenExpirationDate('');
var expD3: Promise<null | Date> = svc.getTokenExpirationDate(Promise.resolve(''));

Added tests to ensure the above using tsd.

I have also added additional tests to cover for the behavior that got broken in 5.1.1.

Checklist

@codecov
Copy link

codecov bot commented Dec 20, 2022

Codecov Report

Base: 85.71% // Head: 85.71% // No change to project coverage 👍

Coverage data is based on head (bff7678) compared to base (29045be).
Patch has no changes to coverable lines.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #759   +/-   ##
=======================================
  Coverage   85.71%   85.71%           
=======================================
  Files           2        2           
  Lines           7        7           
=======================================
  Hits            6        6           
  Misses          1        1           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

ewanharris
ewanharris previously approved these changes Dec 20, 2022
@frederikprijck frederikprijck merged commit 283457b into main Dec 20, 2022
@frederikprijck frederikprijck deleted the fix/5.1.1-types branch December 20, 2022 15:37
@frederikprijck frederikprijck mentioned this pull request Dec 20, 2022
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

Successfully merging this pull request may close these issues.

None yet

2 participants