scute.users manages the app's users with the secret key. Every method returns the API's JSON as a Hash (or an Array where noted) and raises Scute::APIError on an error answer.
scute = Scute::Client.newuser = scute.users.create("ada@example.com", meta: { plan: "pro" })scute.users.update(user["id"], user_meta: { plan: "team" })Create and invite#
scute.users.create("ada@example.com", meta: { plan: "pro" })scute.users.create("+14155550123")scute.users.invite("bob@example.com") # also sends an invitation (magic link)| Method | Request |
|---|---|
| create(identifier, meta: nil) | POST /v1/auth/:app_id/users with identifier and user_meta |
| invite(identifier, meta: nil) | POST /v1/:app_id/users/invite with identifier and user_meta |
identifier is an email or a phone number. Meta keys must be user meta fields the app declares.
Find and list#
scute.users.get(id)scute.users.find_by_identifier("ada@example.com") # or "+14155550123"; nil when nobody uses itscute.users.list(page: 1)list(**params) sends the keyword arguments as the query string of GET /v1/:app_id/users (for example page, per_page and status; find_by_identifier uses q and limit). nil values are dropped.
find_by_identifier(identifier) searches with list(q:, limit: 100, page:) and keeps only an exact match:
- An identifier with @ is compared as an email, case-insensitive.
- Anything else is compared as digits only, so include the country code.
- It looks at up to 10 pages of 100 users and returns nil when nothing matches.
- A blank identifier returns nil without a call. It never creates a user.
Update, deactivate, delete#
scute.users.update(id, user_meta: { plan: "team" })scute.users.deactivate(id)scute.users.activate(id)scute.users.delete(id)update(id, **attributes) sends the keyword arguments as the body of PATCH /v1/:app_id/users/:id.
Previous accounts and merge#
A deleted user who signs in again gets a fresh account with a new id. previous_accounts(id) returns their earlier, deleted accounts in this app, newest first, as an Array. Each entry has the id, status, created_at, deleted_at, merged_into (once merged), the number of roles and passkeys it holds, and its MFA methods.
previous = scute.users.previous_accounts(user_id)result = scute.users.merge(user_id, from: previous.first["id"])result["moved"] # { "roles" => 2, ... }merge(id, from:) moves roles, object roles, passkeys, MFA methods and unused backup codes into the live account. Meta and authorization attributes merge, and the live account wins where both have a value. History stays on the old account. It returns user_id, merged and moved.
| Error code | When |
|---|---|
| already_merged | The old account was merged before. An account merges once. |
Someone deactivated and then deleted cannot sign in again this way: sign-in answers account_deactivated.
Sign in as a user (support access)#
Off until the app turns impersonation on in its authorization settings. The session is short, never refreshed, and its token names who is really acting (Session#actor).
tokens = scute.users.impersonate( user_id, reason: "Ticket 4411", actor: { email: "support@acme.com" }, minutes: 15)scute.users.impersonations(user_id) # sessions as this user that have not endedscute.users.stop_impersonating(user_id) # end all of themscute.users.stop_impersonating(user_id, session_id: "...") # end oneThe answer holds the access token as the user, the session id and the details. Hand the tokens to the browser: scute.beginImpersonation(tokens) in @scute/js-core (see JavaScript SDK).
Client IP#
Pass the end user's IP address on calls that start a sign-in or create a user, so Scute checks it against the workspace's IP rules:
scute.with_client_ip(request.remote_ip).users.create("ada@example.com")