Skip to content

Commit 1d1c0cb

Browse files
committed
Use @types/aws-lambda instead of duplicating types here
1 parent 658d02b commit 1d1c0cb

File tree

3 files changed

+11
-36
lines changed

3 files changed

+11
-36
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
},
1111
"license": "Apache-2.0",
1212
"dependencies": {
13+
"@types/aws-lambda": "^8.10.46",
1314
"@types/node": "^12.12.15",
1415
"aws-sdk": "^2.585.0"
1516
}

src/index.ts

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
import { CognitoUserPoolTriggerEvent } from 'aws-lambda';
12
import { AWSError, CognitoIdentityServiceProvider } from 'aws-sdk';
23
import { AdminInitiateAuthRequest } from 'aws-sdk/clients/cognitoidentityserviceprovider';
34

4-
import { CognitoEvent, UserMigrationAuthenticationEvent, UserMigrationForgotPasswordEvent } from './types/event';
5-
65
/**
76
* AWS region in which your User Pools are deployed
87
*/
@@ -76,19 +75,19 @@ async function lookupUser(username: string): Promise<User | undefined> {
7675
return user;
7776
}
7877

79-
async function onUserMigrationAuthentication(event: UserMigrationAuthenticationEvent) {
78+
async function onUserMigrationAuthentication(event: CognitoUserPoolTriggerEvent) {
8079
// authenticate the user with your existing user directory service
81-
const user = await authenticateUser(event.userName, event.request.password);
80+
const user = await authenticateUser(event.userName!, event.request.password!);
8281
if (!user) {
8382
throw new Error('Bad credentials');
8483
}
8584

8685
event.response.userAttributes = {
8786
// old_username: user.userName,
8887
// 'custom:tenant': user.userAttributes['custom:tenant'],
89-
email: user.userAttributes.email,
88+
email: user.userAttributes.email!,
9089
email_verified: 'true',
91-
preferred_username: user.userAttributes.preferred_username,
90+
preferred_username: user.userAttributes.preferred_username!,
9291
};
9392
event.response.finalUserStatus = 'CONFIRMED';
9493
event.response.messageAction = 'SUPPRESS';
@@ -97,19 +96,19 @@ async function onUserMigrationAuthentication(event: UserMigrationAuthenticationE
9796
return event;
9897
}
9998

100-
async function onUserMigrationForgotPassword(event: UserMigrationForgotPasswordEvent) {
99+
async function onUserMigrationForgotPassword(event: CognitoUserPoolTriggerEvent) {
101100
// Lookup the user in your existing user directory service
102-
const user = await lookupUser(event.userName);
101+
const user = await lookupUser(event.userName!);
103102
if (!user) {
104103
throw new Error('Bad credentials');
105104
}
106105

107106
event.response.userAttributes = {
108107
// old_username: user.userName,
109108
// 'custom:tenant': user.userAttributes['custom:tenant'],
110-
email: user.userAttributes.email,
109+
email: user.userAttributes.email!,
111110
email_verified: 'true',
112-
preferred_username: user.userAttributes.preferred_username,
111+
preferred_username: user.userAttributes.preferred_username!,
113112
};
114113
event.response.messageAction = 'SUPPRESS';
115114

@@ -118,7 +117,7 @@ async function onUserMigrationForgotPassword(event: UserMigrationForgotPasswordE
118117
return event;
119118
}
120119

121-
export const handler = async (event: CognitoEvent): Promise<CognitoEvent> => {
120+
export const handler = async (event: CognitoUserPoolTriggerEvent): Promise<CognitoUserPoolTriggerEvent> => {
122121
switch (event.triggerSource) {
123122
case 'UserMigration_Authentication':
124123
return onUserMigrationAuthentication(event);

src/types/event.ts

-25
This file was deleted.

0 commit comments

Comments
 (0)