Overview

The UserInvitation struct represents a pending invitation sent to a user to join the platform or organization.

Definition

pub struct UserInvitation {
    pub id: String,
    pub email: String,
    pub role: Option<String>,
    pub organization_id: Option<String>,
    pub invited_at: String,
    pub expires_at: String,
}

Fields

id
String
required
Unique identifier for the invitation.
email
String
required
Email address of the invited user.
role
Option<String>
The role assigned to the user upon acceptance. Can be a predefined role or custom role ID.
organization_id
Option<String>
ID of the organization the user is being invited to. If None, it’s a platform-level invitation.
invited_at
String
required
ISO 8601 timestamp of when the invitation was created.
expires_at
String
required
ISO 8601 timestamp of when the invitation expires. Typically 7 days from creation.

Usage Example

use wacht::api::users::*;

// Fetch all pending invitations
let invitations = fetch_invitations(None).await?;

for invitation in invitations.data {
    println!("Invitation to: {}", invitation.email);
    println!("  ID: {}", invitation.id);
    println!("  Role: {}", invitation.role.unwrap_or("default".to_string()));
    println!("  Expires: {}", invitation.expires_at);

    if let Some(org_id) = invitation.organization_id {
        println!("  Organization: {}", org_id);
    }
}

// Check if invitation is expired
use chrono::{DateTime, Utc};
let expires = DateTime::parse_from_rfc3339(&invitation.expires_at).unwrap();
if expires < Utc::now() {
    println!("Invitation has expired");
}

See Also