JavaScript SDK

User profile

Read the signed-in user, update profile fields (metafields), and manage alternate phone numbers.

Read the user#

const { data, error } = await scute.getUser();// data.user: ScuteUserData

getUser(accessToken?) reads the user of the current session, or of the token you pass (on a server). It returns InvalidAuthTokenError for a token the API refuses with 401.

FieldType
idstring | number
status"active", "pending" or "inactive"
email, phonestring | null
email_verified, phone_verifiedboolean
webauthn_enabledboolean
metaRecord<string, string | boolean | number> | null
sessionsScuteUserSession[]
required_fields{ field, required }[]
last_used_at, signup_datestring

Profile fields (metafields)#

The app defines typed profile fields in the dashboard. Their schema is in the app settings:

const { data: app } = await scute.getAppData();for (const field of app.user_meta_data_schema) {  // { id, name, field_name, field_type, required, visible_profile, visible_registration }}

field_type is one of string, boolean, integer, date, phone, email, text, url. Values are keyed by field_name.

const { data, error } = await scute.updateUserMeta({ company: "Acme", newsletter: true });// data.user: the updated user

On a validation failure the API answers with error.json.errors, a list of { key, message }.

getUserMetafieldState(userId) returns { meta: boolean }: whether the user still has required fields to fill.

Set fields at sign-up with signUp(identifier, { userMeta }), sendRegisterMagicLink(identifier, userMeta) or sendRegisterOtp(identifier, userMeta).

Alternate phone numbers#

Verified extra numbers for SMS. A number is added only after the code sent to it is verified.

const { data } = await scute.addAlternatePhone("+14155550100", "work");// an SMS code went to the number; data.challenge_tokenawait scute.verifyAlternatePhoneChallenge(data.challenge_token, code);const { data: list } = await scute.listAlternatePhones();// list.alternate_phones: [{ phone, label?, verified_at?, usable_for_login? }]await scute.removeAlternatePhone("+14155550100");

Phone numbers are E.164; 10-digit US numbers are accepted. Removing a number needs no re-verification. Error codes from the API include invalid_phone, phone_is_canonical, phone_already_registered, alternate_phone_cap_exceeded and alternate_phone_not_found.

For React, useUserProfile and useAlternatePhones wrap these calls. See Account hooks.