This repository has been archived on 2025-12-11. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
tasker/tasker-server/src/handlers/createUser.ts

42 lines
1.2 KiB
TypeScript

import { fetchRandomTeamId } from "@/lib/util";
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocument, PutCommandInput } from "@aws-sdk/lib-dynamodb";
import { v4 as uuidv4 } from "uuid";
const SLS_REGION = process.env.SLS_REGION;
const TASKER_USER_TABLE_NAME = process.env.TASKER_USER_TABLE_NAME || "";
const client = new DynamoDBClient({ region: SLS_REGION });
const docClient = DynamoDBDocument.from(client);
export const handler = async (event: any): Promise<any> => {
const username =
event.request.userAttributes["preferred_username"] || event.userName;
const cognitoId = event.userName;
const teamId = await fetchRandomTeamId();
try {
const newUser = {
category: "users",
cognitoId,
userId: `user#${uuidv4()}`,
username,
profilePictureUrl: "i0.jpg",
teamId,
};
const params: PutCommandInput = {
TableName: TASKER_USER_TABLE_NAME,
Item: newUser,
};
await docClient.put(params);
console.info(`User ${username} created with teamId ${teamId}`);
} catch (error: any) {
throw new Error(`Error creating user: ${error.message}`);
}
return event;
};