Skip to main content

User Profile

User profile management in the @espressif/rainmaker-base-sdk allows you to retrieve and update user information and manage phone numbers.

note

The userInstance mentioned below refers to the ESPRMUser instance obtained during User Sign in.

User Information

Get User Info

Retrieve user information, optionally including custom data, using the getUserInfo method.

/*
- withCustomData: Optional flag indicating whether to include custom data in the response.
- true: Includes custom data in the response
- false or omitted: Returns user information without custom data (default)
*/

try {
const userInfo = await userInstance.getUserInfo(true);
console.log("User info fetched successfully:", userInfo);
} catch (error) {
console.error("Error fetching user info:", error);
}

Parameters:

ParameterTypeRequiredDescription
withCustomDatabooleanNoOptional flag indicating whether to include custom data in the response. Defaults to false. Pass true to include custom data in the same call.

Returns: Promise<ESPRMUserInfo> - A promise that resolves to an ESPRMUserInfo object containing the user information.

Example: Get User Info Without Custom Data

try {
const userInfo = await userInstance.getUserInfo();
// or
const userInfo = await userInstance.getUserInfo(false);
console.log("User info (without custom data):", userInfo);
} catch (error) {
console.error("Error fetching user info:", error);
}

Example: Get User Info With Custom Data

try {
const userInfo = await userInstance.getUserInfo(true);
console.log("User info (with custom data):", userInfo);
} catch (error) {
console.error("Error fetching user info:", error);
}

Update Name

Update the name associated with the current user using the updateName method.

/*
- newName: The new name to be set for the user.
*/

try {
const response = await userInstance.updateName("John Doe");
console.log("Name updated successfully:", response);
} catch (error) {
console.error("Error updating name:", error);
}

Phone Number Management

Setting up a phone number is a two-step process:

  1. Set Phone Number - Send an OTP to the phone number
  2. Confirm Phone Number - Verify the phone number using the OTP received

Step 1: Set Phone Number

Update the phone number associated with the current user using the setPhoneNumber method. This will send an OTP to the provided phone number.

/*
- phoneNumber: The new phone number to be set for the user.
*/

try {
const response = await userInstance.setPhoneNumber("+1234567890");
console.log("OTP sent to phone number successfully:", response);
} catch (error) {
console.error("Error setting phone number:", error);
}

Step 2: Confirm Phone Number

Confirm the phone number associated with the user by providing a verification code using the confirmPhoneNumber method. Use the OTP received from the setPhoneNumber step to verify and complete the phone number setup.

/*
- verificationCode: The verification code (OTP) sent to the user for confirming the phone number.
*/

try {
const response = await userInstance.confirmPhoneNumber(verificationCode);
console.log("Phone number confirmed successfully:", response);
} catch (error) {
console.error("Error confirming phone number:", error);
}

On this page