feat: Add Cognito user pool name parameter and update API handlers to include CORS headers

This commit is contained in:
2024-11-23 11:12:46 +02:00
parent 59c0c97252
commit 5f9ee29c8d
14 changed files with 103 additions and 47 deletions

View File

@@ -10,8 +10,10 @@ const client = new DynamoDBClient({ region: SLS_REGION });
const docClient = DynamoDBDocument.from(client);
export const handler = async (event: any): Promise<any> => {
const { username, cognitoId } = JSON.parse(event.body);
const teamId = fetchRandomTeamId();
const username =
event.request.userAttributes["preferred_username"] || event.userName;
const cognitoId = event.userName;
const teamId = await fetchRandomTeamId();
try {
const newUser = {
@@ -30,18 +32,10 @@ export const handler = async (event: any): Promise<any> => {
await docClient.put(params);
return {
statusCode: 201,
headers: { "Content-Type": "application/json" },
body: JSON.stringify(newUser),
};
console.info(`User ${username} created with teamId ${teamId}`);
} catch (error: any) {
return {
statusCode: 500,
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
message: `Error creating user: ${error.message}`,
}),
};
throw new Error(`Error creating user: ${error.message}`);
}
return event;
};