awslabs / cognito-at-edge

Serverless authentication solution to protect your website or Amplify application
Apache License 2.0
168 stars 54 forks source link

Type mismatch of the status code #34

Closed piotrekwitkowski closed 2 years ago

piotrekwitkowski commented 2 years ago

What happened:

The type of the response returned by the Authenticator doesn't match the CloudFrontRequestHandler response type from the aws-lambda package

What did you expect to have happen:

The types match

How to reproduce this (as precisely and succinctly as possible):

This should work ```ts import { SSMClient, GetParameterCommand } from "@aws-sdk/client-ssm"; import { CloudFrontRequestHandler } from "aws-lambda"; import { Authenticator } from "cognito-at-edge"; const ssm = new SSMClient({ region: process.env.CONFIG_PARAMETER_REGION }); const authenticatorPromise = ssm .send(new GetParameterCommand({ Name: process.env.CONFIG_PARAMETER_NAME })) .then(config => new Authenticator({ ...JSON.parse(config.Parameter!.Value!), logLevel: 'info' })); export const handler: CloudFrontRequestHandler = async event => { try { const authenticator = await authenticatorPromise; return await authenticator.handle(event); } catch (error) { console.error(error); return { body: '401 Unauthorized', status: '401' }; } }; ```

Anything else you think we should know?

PR will be provided

Environment: