Skip to main content

Custom Data

Store app-specific user fields, geo location, and timezone in RainMaker.

note

userInstance — ESPRMUser from User sign in.

What This Module Does ?​

Manages custom key-value data on the user record with optional read/write permissions, plus helpers for geo coordinates and timezone.

Use this when profile fields in User Profile are not enough, or you need location/timezone for provisioning defaults.

Expected outcome: Custom data persisted on the user; timezone can apply automatically during device provisioning.

Common Workflows​

Read and write custom data​

const customData = await userInstance.getCustomData();

await userInstance.setCustomData({
name: {
value: "jack",
perms: [{ read: ["user", "admin"], write: ["user"] }],
},
});

await userInstance.deleteCustomData("exampleKey");
await userInstance.deleteCustomDataKey("exampleKey");
await userInstance.deleteCustomDataPermissions("exampleKey");

Geo coordinates​

await userInstance.setGeoCoordinates({
latitude: 28.6139,
longitude: 77.209,
});

const geo = await userInstance.getGeoCoordinates();

Time zone​

await userInstance.setTimeZone("Asia/Kolkata");

If set, new devices provisioned by this user can inherit this timezone.

Error Handling​

try {
await userInstance.setCustomData(customDataRequest);
} catch (error) {
console.error("Failed to save custom data:", error);
}

Use JSON-serializable values only; avoid circular structures.

Best Practices​

  1. Define stable key names across app versions
  2. Set timezone early if provisioning should use it by default
  3. Do not store secrets in custom data
  4. Scope permissions when multiple clients read the same user record

On this page