Users API Guide
Learn how to manage users using the Wacht Rust SDK.
Prerequisites
Before using any API methods, you must initialize the SDK:
use wacht :: WachtClient ;
#[tokio :: main]
async fn main () -> Result <(), Box < dyn std :: error :: Error >> {
// Initialize the client with an API key
let client = WachtClient :: new ( "wk_live_..." );
// Now you can use the API
Ok (())
}
List Users
Retrieve a paginated list of users from your deployment.
Basic List
use wacht :: WachtClient ;
// Initialize client
let client = WachtClient :: new ( "wk_live_..." );
// Fetch all users (default pagination)
let users = client . users () . fetch_users () . send () . await ? ;
println! ( "Total users: {}" , users . data . len ());
for user in users . data {
println! ( "{} {}" , user . first_name, user . last_name);
}
With Pagination and Filters
// Fetch users with builder options
let users = client . users () . fetch_users ()
. limit ( 50 )
. offset ( 0 )
. search ( "john" )
. sort_key ( "created_at" )
. sort_order ( "desc" )
. send ()
. await ? ;
println! ( "Has more: {}" , users . has_more);
Builder Methods
Number of results to return (max 100).
Number of results to skip.
Search query to filter results.
Sort order (“asc” or “desc”).
Get User Details
Retrieve complete information about a user including all emails, phones, and social connections.
let details = client . users () . fetch_user_details ( "user_123" ) . send () . await ? ;
println! ( "User: {} {}" , details . first_name, details . last_name);
println! ( "Email: {:?}" , details . primary_email_address);
println! ( "Has password: {}" , details . has_password);
println! ( "Emails: {}" , details . email_addresses . len ());
Create User
Create a new user in your deployment.
Basic User Creation
use wacht :: models :: CreateUserRequest ;
let user = client . users () . create_user ( CreateUserRequest :: new (
"John" . to_string (),
"Doe" . to_string ()
))
. send ()
. await ? ;
println! ( "Created user: {}" , user . id);
With Optional Fields
use wacht :: models :: CreateUserRequest ;
let request = CreateUserRequest {
first_name : "Jane" . to_string (),
last_name : "Smith" . to_string (),
email_address : Some ( "jane@example.com" . to_string ()),
phone_number : Some ( "+1234567890" . to_string ()),
username : Some ( "janesmith" . to_string ()),
password : Some ( "securePassword123" . to_string ()),
skip_password_check : false ,
};
let user = client . users () . create_user ( request )
. send ()
. await ? ;
request
CreateUserRequest
required
Skip password validation (default: false).
Update User
Update an existing user’s information. Only provided fields will be updated.
use wacht :: models :: UpdateUserRequest ;
let updated = client . users () . update_user (
"user_123" ,
UpdateUserRequest {
first_name : Some ( "Jane" . to_string ()),
last_name : Some ( "Smith" . to_string ()),
username : Some ( "janesmith" . to_string ()),
.. Default :: default ()
}
)
. send ()
. await ? ;
Available Update Fields
request
UpdateUserRequest
required
public_metadata
Option<serde_json::Value>
Public metadata to assign.
private_metadata
Option<serde_json::Value>
Private metadata to assign (never visible to frontend).
Set to true to disable the user’s account entirely.
Update Password
Update a user’s password.
use wacht :: models :: UpdatePasswordRequest ;
client . users () . update_password (
"user_123" ,
UpdatePasswordRequest {
new_password : "newSecurePassword" . to_string (),
skip_password_check : false ,
}
)
. send ()
. await ? ;
Delete User
Permanently delete a user. This action cannot be undone.
client . users () . delete_user ( "user_123" ) . send () . await ? ;
Manage Emails
Add Email Address
let email = client . users () . emails () . add_email (
"user_123" ,
"newemail@example.com" ,
None // verification_strategy
)
. send ()
. await ? ;
Update Email
let email = client . users () . emails () . update_email (
"user_123" ,
"email_456" ,
Some ( "updated@example.com" . to_string ()),
Some ( true ) // set as primary
)
. send ()
. await ? ;
Delete Email
client . users () . emails () . delete_email ( "user_123" , "email_456" ) . send () . await ? ;
Manage Phone Numbers
Add Phone
let phone = client . users () . phones () . add_phone (
"user_123" ,
"+1234567890" ,
"+1"
)
. send ()
. await ? ;
Update Phone
let phone = client . users () . phones () . update_phone (
"user_123" ,
"phone_456" ,
Some ( "+1987654321" . to_string ()),
Some ( "+1" . to_string ()),
Some ( true ), // verified
Some ( true ) // set as primary
)
. send ()
. await ? ;
Delete Phone
client . users () . phones () . delete_phone ( "user_123" , "phone_456" ) . send () . await ? ;
Social Connections
Delete a social connection (OAuth provider) from a user’s account.
client . users () . social_connections () . delete_connection (
"user_123" ,
"connection_456"
)
. send ()
. await ? ;
Error Handling
All SDK methods return a Result<T, Error>:
use wacht :: Error ;
match client . users () . fetch_user_details ( "invalid_id" ) . send () . await {
Ok ( details ) => println! ( "User: {}" , details . first_name),
Err ( Error :: Api { status , message , .. }) => {
eprintln! ( "API Error {}: {}" , status , message );
}
Err ( Error :: Request ( e )) => {
eprintln! ( "Network error: {}" , e );
}
Err ( e ) => {
eprintln! ( "Other error: {}" , e );
}
}