awslabs / aws-jwt-verify

JS library for verifying JWTs signed by Amazon Cognito, and any OIDC-compatible IDP that signs JWTs with RS256, RS384, and RS512
Apache License 2.0
594 stars 43 forks source link

[BUG] Type error with CognitoJwtVerifier.create #120

Closed etroynov closed 1 year ago

etroynov commented 1 year ago

When i try use configuration from var i got an error:

Screenshot 2023-03-29 at 13 38 45

But when i do it directly:

Screenshot 2023-03-29 at 13 39 15

everything is fine.

Versions

ottokruse commented 1 year ago

This is expected I think, because if you predefine the config object like you did, TypeScript types each member as string but tokenUse must be access or id, a mere string won't do.

This should work:

const config = {
    userPoolId: "xxxxxxxxxxx",
    tokenUse: "access" as const, // changed
    clientId: "xxxxxxxxxxxx"
}

const verifier = CognitoJwtVerifier.create(config);
ottokruse commented 1 year ago

Even more info: https://mariusschulz.com/blog/const-assertions-in-literal-expressions-in-typescript