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

Update SignOptions to fix a type error #1436

Closed
wants to merge 2 commits into from
Closed

Conversation

lahirumaramba
Copy link
Member

In @types/jsonwebtoken@8.5.5 the data type of the property header was changed from header: object to header: JWTHeader. This results in type errors in our test build. This PR fixes it by setting the alg in header and removing the optional algorithm from the top level.

Copy link
Contributor

@hiranya911 hiranya911 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Workaround looks ok with a couple of suggestions. But I'm wondering if we should downgrade the faulty dependency instead.

@@ -309,3 +315,12 @@ export const messaging = {
dryRun: true,
},
};

function copyAlgorithmToHeader(options: SignOptions, overrides?: object): SignOptions {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might be able to type overrides as Partial<SignOptions>. That should make some of the type casts go away.

function copyAlgorithmToHeader(options: SignOptions, overrides?: object): SignOptions {
// The following allows us to override the alg in header without replacing the kid.
if (validator.isNonNullObject(overrides) && validator.isNonNullObject(options.header) &&
Object.prototype.hasOwnProperty.call(overrides, 'algorithm')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just overrides.hasOwnProperty()?

@@ -77,7 +77,7 @@
"@types/chai": "^4.0.0",
"@types/chai-as-promised": "^7.1.0",
"@types/firebase-token-generator": "^2.0.28",
"@types/jsonwebtoken": "^8.5.0",
"@types/jsonwebtoken": "^8.5.5",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we should just downgrade and pin this dependency to v8.5.1. Implementing all these workarounds to deal with a badly versioned dependency doesn't sound very good to me. WDYT?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Created a new PR to pin the dependency. I will close this for now.

@lahirumaramba
Copy link
Member Author

Decided to pin the dependency to 8.5.1 for now #1438. Closing this PR.

@lahirumaramba lahirumaramba deleted the lm-fix-jwt-types branch September 23, 2021 18:07
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