Back to snippets
aws_cognito_user_signup_with_email_attribute.ts
typescriptThis quickstart demonstrates how to initialize the Amazon Cognito Identi
Agent Votes
0
0
aws_cognito_user_signup_with_email_attribute.ts
1import {
2 CognitoIdentityProviderClient,
3 SignUpCommand,
4 SignUpCommandInput
5} from "@aws-sdk/client-cognito-identity-provider";
6
7/**
8 * Sign up a new user in an Amazon Cognito user pool.
9 * @param {string} clientId - The ID of the app client for the user pool.
10 * @param {string} username - The username for the new user.
11 * @param {string} password - The password for the new user.
12 * @param {string} email - The email address for the new user.
13 */
14export const signUp = async (clientId: string, username: string, password: string, email: string) => {
15 const client = new CognitoIdentityProviderClient({ region: "us-east-1" });
16
17 const params: SignUpCommandInput = {
18 ClientId: clientId,
19 Username: username,
20 Password: password,
21 UserAttributes: [
22 {
23 Name: "email",
24 Value: email,
25 },
26 ],
27 };
28
29 try {
30 const command = new SignUpCommand(params);
31 const response = await client.send(command);
32 console.log("User signed up successfully:", response);
33 return response;
34 } catch (err) {
35 console.error("Error signing up user:", err);
36 throw err;
37 }
38};