Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

fix: error on creating Cognito authorizers for V1 AWS APIs #1191

Merged
merged 2 commits into from
Oct 16, 2024

Conversation

greenlynx
Copy link
Contributor

Fixes the error discussed in sst/sst#4058

@jayair
Copy link
Contributor

jayair commented Oct 4, 2024

Thanks

@jamesleech
Copy link

I've got this same issue in V1,

This is causing an issue when trying to create a Cognito Authoriser.
When setting up a Cognito Authoriser we do not required a function, and in fact errors before this line if you try to add a token/request Function.

fn? will be rightly undefined in this case, and should not be force to be non null.

If I revert this change, and do the below, my authoriser is setup correctly and works.

api.addAuthorizer({
    name: "my-authorizer",
    userPools: [myUserPoolArn],
  });

@jamesleech
Copy link

it does look like this issue could also be in V2 (http) of the apigateway function also.

@greenlynx
Copy link
Contributor Author

I haven't tested it, but I don't think this is an issue in V2 API Gateway - in there, as the code currently stands, it looks like fn will only be undefined if lamb is undefined, and the fn! line is only hit if lamb is truthy. I think there's an argument to be made for avoiding the use of the non-null assertion operator as far as possible, to avoid bugs creeping in inadvertantly in future if the logic changes - but I'd rather keep this PR focused on fixing the specific bug we're hitting.

Maintainers - are you happy with this PR? Do I need to do anything further to get it merged?

@jamesleech
Copy link

I haven't tested it, but I don't think this is an issue in V2 API Gateway - in there, as the code currently stands, it looks like fn will only be undefined if lamb is undefined, and the fn! line is only hit if lamb is truthy. I think there's an argument to be made for avoiding the use of the non-null assertion operator as far as possible, to avoid bugs creeping in inadvertantly in future if the logic changes - but I'd rather keep this PR focused on fixing the specific bug we're hitting.

Maintainers - are you happy with this PR? Do I need to do anything further to get it merged?

"argument to be made for avoiding the use of the non-null assertion operator as far as possible" 100% Agree.

Would appreciate this PR being released, as I've currently out of scoped auth for a specific API route because of this bug for a project I'm working on to carry on to meet project deadlines, we'll loop back once this is merged and released.

@greenlynx
Copy link
Contributor Author

Would appreciate this PR being released, as I've currently out of scoped auth for a specific API route because of this bug for a project I'm working on to carry on to meet project deadlines, we'll loop back once this is merged and released.

Me too, as it's blocking me as well. I don't know how to proceed though - I've never contributed to this project before and am not sure of the process.

@fwang fwang merged commit 8a40f6f into sst:dev Oct 16, 2024
@fwang
Copy link
Contributor

fwang commented Oct 16, 2024

Will be in v3.2.29 - sorry about the delay!

@greenlynx greenlynx deleted the fix-cognito-auth-for-v1-aws-api branch October 16, 2024 15:51
@jamesleech
Copy link

thanks @fwang ! great news

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to reference an existing authorizer function for ApiGatewayV1
4 participants