or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

authentication-lifecycle.mddevice-management.mdindex.mdmulti-factor-authentication.mdoauth-social-authentication.mdpassword-management.mdserver-side-apis.mdsession-management.mduser-management.mdwebauthn-credentials.md
tile.json

user-management.mddocs/

User Management

User profile operations including attribute management, verification, and account operations.

Get Current User

Retrieve information about the currently authenticated user.

function getCurrentUser(): Promise<AuthUser>;

interface AuthUser {
  username: string;
  userId: string;
  signInDetails?: AuthSignInDetails;
}

interface AuthSignInDetails {
  loginId?: string;
  authFlowType?: AuthFlowType;
}

Usage Example

import { getCurrentUser } from "@aws-amplify/auth";

try {
  const user = await getCurrentUser();
  console.log("Current user:", user.username);
  console.log("User ID:", user.userId);
} catch (error) {
  console.log("No user signed in");
}

Fetch User Attributes

Get all attributes for the current user.

function fetchUserAttributes(): Promise<FetchUserAttributesOutput>;

type FetchUserAttributesOutput = Record<UserAttributeKey, string>;

Usage Example

import { fetchUserAttributes } from "@aws-amplify/auth";

const attributes = await fetchUserAttributes();

console.log("User email:", attributes.email);
console.log("User name:", attributes.name);
console.log("Phone number:", attributes.phone_number);

// All available attributes
Object.entries(attributes).forEach(([key, value]) => {
  console.log(`${key}: ${value}`);
});

Update User Attributes

Update multiple user attributes at once.

function updateUserAttributes(input: UpdateUserAttributesInput): Promise<UpdateUserAttributesOutput>;

interface UpdateUserAttributesInput {
  userAttributes: Record<UserAttributeKey, string>;
  clientMetadata?: Record<string, string>;
}

interface UpdateUserAttributesOutput {
  [key: UserAttributeKey]: {
    isUpdated: boolean;
    nextStep: {
      updateAttributeStep: 'CONFIRM_ATTRIBUTE_WITH_CODE' | 'DONE';
      codeDeliveryDetails?: CodeDeliveryDetails;
    };
  };
}

Usage Example

import { updateUserAttributes } from "@aws-amplify/auth";

const result = await updateUserAttributes({
  userAttributes: {
    name: "John Updated",
    email: "newemail@example.com",
    phone_number: "+19876543210"
  }
});

// Check which attributes need verification
Object.entries(result).forEach(([attribute, details]) => {
  if (details.nextStep.updateAttributeStep === 'CONFIRM_ATTRIBUTE_WITH_CODE') {
    console.log(`Verification code sent for ${attribute} to ${details.nextStep.codeDeliveryDetails?.destination}`);
  } else {
    console.log(`${attribute} updated successfully`);
  }
});

Update User Attribute

Update a single user attribute.

function updateUserAttribute(input: UpdateUserAttributeInput): Promise<UpdateUserAttributeOutput>;

interface UpdateUserAttributeInput {
  userAttribute: {
    attributeKey: UserAttributeKey;
    value: string;
  };
  clientMetadata?: Record<string, string>;
}

interface UpdateUserAttributeOutput {
  isUpdated: boolean;
  nextStep: {
    updateAttributeStep: 'CONFIRM_ATTRIBUTE_WITH_CODE' | 'DONE';
    codeDeliveryDetails?: CodeDeliveryDetails;
  };
}

Usage Example

import { updateUserAttribute } from "@aws-amplify/auth";

const result = await updateUserAttribute({
  userAttribute: {
    attributeKey: 'email',
    value: 'newemail@example.com'
  }
});

if (result.nextStep.updateAttributeStep === 'CONFIRM_ATTRIBUTE_WITH_CODE') {
  console.log(`Verification code sent to: ${result.nextStep.codeDeliveryDetails?.destination}`);
} else {
  console.log("Email updated successfully");
}

Confirm User Attribute

Confirm a user attribute change using a verification code.

function confirmUserAttribute(input: ConfirmUserAttributeInput): Promise<void>;

interface ConfirmUserAttributeInput {
  userAttributeKey: VerifiableUserAttributeKey;
  confirmationCode: string;
}

Usage Example

import { confirmUserAttribute } from "@aws-amplify/auth";

await confirmUserAttribute({
  userAttributeKey: 'email',
  confirmationCode: '123456'
});

console.log("Email verified successfully");

Send User Attribute Verification Code

Send a verification code for a user attribute that requires verification.

function sendUserAttributeVerificationCode(input: SendUserAttributeVerificationCodeInput): Promise<SendUserAttributeVerificationCodeOutput>;

interface SendUserAttributeVerificationCodeInput {
  userAttributeKey: VerifiableUserAttributeKey;
  clientMetadata?: Record<string, string>;
}

interface SendUserAttributeVerificationCodeOutput {
  destination?: string;
  deliveryMedium?: 'EMAIL' | 'SMS';
  attributeName?: string;
}

Usage Example

import { sendUserAttributeVerificationCode } from "@aws-amplify/auth";

const codeDelivery = await sendUserAttributeVerificationCode({
  userAttributeKey: 'phone_number'
});

console.log(`Verification code sent to: ${codeDelivery.destination}`);

Delete User Attributes

Delete user attributes from the user profile.

function deleteUserAttributes(input: DeleteUserAttributesInput): Promise<void>;

interface DeleteUserAttributesInput {
  userAttributeKeys: UserAttributeKey[];
}

Usage Example

import { deleteUserAttributes } from "@aws-amplify/auth";

await deleteUserAttributes({
  userAttributeKeys: ['middle_name', 'nickname', 'website']
});

console.log("Attributes deleted successfully");

Delete User

Permanently delete the user account.

function deleteUser(): Promise<void>;

Usage Example

import { deleteUser } from "@aws-amplify/auth";

// This is a destructive operation - consider showing confirmation dialog
const confirmDelete = confirm("Are you sure you want to delete your account? This action cannot be undone.");

if (confirmDelete) {
  await deleteUser();
  console.log("User account deleted successfully");
}

User Attribute Types

Available user attribute keys and their purposes:

type UserAttributeKey = 
  | 'address'           // Full mailing address
  | 'birthdate'         // Date of birth (YYYY-MM-DD)
  | 'email'             // Email address (verifiable)
  | 'family_name'       // Last name
  | 'gender'            // Gender
  | 'given_name'        // First name
  | 'locale'            // Locale (language/country)
  | 'middle_name'       // Middle name
  | 'name'              // Full name
  | 'nickname'          // Nickname
  | 'phone_number'      // Phone number (verifiable, E.164 format)
  | 'picture'           // Profile picture URL
  | 'preferred_username'// Preferred username
  | 'profile'           // Profile page URL
  | 'sub'               // User identifier (read-only)
  | 'updated_at'        // Last update timestamp (read-only)
  | 'website'           // Website URL
  | 'zoneinfo'          // Time zone
  | (string & {});      // Custom attributes

type VerifiableUserAttributeKey = 'email' | 'phone_number';

Best Practices

Attribute Validation

  • Email addresses must be valid email format
  • Phone numbers should be in E.164 format (+1234567890)
  • Custom attributes must be defined in the User Pool schema
  • Some attributes may be marked as required in the User Pool configuration

Error Handling

import { updateUserAttribute, AuthError } from "@aws-amplify/auth";

try {
  await updateUserAttribute({
    userAttribute: {
      attributeKey: 'email',
      value: 'invalid-email'
    }
  });
} catch (error) {
  if (error instanceof AuthError) {
    switch (error.name) {
      case 'InvalidParameterException':
        console.log('Invalid email format');
        break;
      case 'NotAuthorizedException':
        console.log('User not authorized');
        break;
      case 'AliasExistsException':
        console.log('Email already in use by another account');
        break;
      default:
        console.log('Update failed:', error.message);
    }
  }
}

Privacy Considerations

  • Only update attributes that the user explicitly wants to change
  • Inform users about which attributes require verification
  • Provide clear feedback about verification requirements
  • Handle verification timeouts and allow code resending