supabase_auth_redux/models/
user.rs

1use std::collections::HashMap;
2
3use serde::{Deserialize, Serialize};
4use uuid::Uuid;
5
6/// Represents a user in the Supabase Auth system
7///
8/// This struct contains all the information about a user including their
9/// authentication status, contact information, and metadata.
10#[derive(Debug, Clone, Default, Deserialize, Serialize, PartialEq, Eq)]
11#[serde(default)]
12pub struct UserSchema {
13    /// Unique identifier for the user
14    pub id: Uuid,
15
16    /// Audience claim for JWT (typically the API URL)
17    pub aud: String,
18    /// User's role in the system (e.g., "authenticated")
19    pub role: String,
20    /// User's primary contact email. In most cases you can uniquely identify a user by their email address, but not in all cases.
21    pub email: Option<String>,
22    /// Timestamp when the email was confirmed
23    #[serde(with = "time::serde::rfc3339::option")]
24    pub email_confirmed_at: Option<time::OffsetDateTime>,
25    /// Timestamp when the user was invited
26    #[serde(with = "time::serde::rfc3339::option")]
27    pub invited_at: Option<time::OffsetDateTime>,
28    /// User's primary contact phone number. In most cases you can uniquely identify a user by their phone number, but not in all cases.
29    pub phone: Option<String>,
30    /// Timestamp when the phone number was confirmed
31    #[serde(with = "time::serde::rfc3339::option")]
32    pub phone_confirmed_at: Option<time::OffsetDateTime>,
33    /// Timestamp when confirmation email/SMS was sent
34    #[serde(with = "time::serde::rfc3339::option")]
35    pub confirmation_sent_at: Option<time::OffsetDateTime>,
36    /// Timestamp when the user confirmed their account
37    #[serde(with = "time::serde::rfc3339::option")]
38    pub confirmed_at: Option<time::OffsetDateTime>,
39    /// Timestamp when password recovery email was sent
40    #[serde(with = "time::serde::rfc3339::option")]
41    pub recovery_sent_at: Option<time::OffsetDateTime>,
42    /// Pending new email address (awaiting confirmation)
43    pub new_email: Option<String>,
44    /// Timestamp when email change confirmation was sent
45    #[serde(with = "time::serde::rfc3339::option")]
46    pub email_change_sent_at: Option<time::OffsetDateTime>,
47    /// Pending new phone number (awaiting confirmation)
48    pub new_phone: Option<String>,
49    /// Timestamp when phone change confirmation was sent
50    #[serde(with = "time::serde::rfc3339::option")]
51    pub phone_change_sent_at: Option<time::OffsetDateTime>,
52    /// Timestamp when reauthentication request was sent
53    #[serde(with = "time::serde::rfc3339::option")]
54    pub reauthentication_sent_at: Option<time::OffsetDateTime>,
55    /// Timestamp of the user's last sign in
56    #[serde(with = "time::serde::rfc3339::option")]
57    pub last_sign_in_at: Option<time::OffsetDateTime>,
58    /// Custom user metadata that can be updated by the user
59    pub user_metadata: Option<HashMap<String, serde_json::Value>>,
60    /// Custom app metadata that can only be updated by service role
61    pub app_metadata: Option<HashMap<String, serde_json::Value>>,
62    /// Multi-factor authentication factors
63    pub factors: Vec<MFAFactorSchema>,
64    /// OAuth/social login identities linked to this user
65    pub identities: Option<Vec<HashMap<String, serde_json::Value>>>,
66    /// Timestamp until which the user is banned
67    #[serde(with = "time::serde::rfc3339::option")]
68    pub banned_until: Option<time::OffsetDateTime>,
69    /// Timestamp when the user was created
70    #[serde(with = "time::serde::rfc3339::option")]
71    pub created_at: Option<time::OffsetDateTime>,
72    /// Timestamp when the user was soft deleted
73    #[serde(with = "time::serde::rfc3339::option")]
74    pub deleted_at: Option<time::OffsetDateTime>,
75    /// Timestamp when the user was last updated
76    #[serde(with = "time::serde::rfc3339::option")]
77    pub updated_at: Option<time::OffsetDateTime>,
78}
79
80/// Multi-factor authentication factor information
81#[derive(Debug, Clone, Deserialize, Serialize, Eq, PartialEq)]
82pub struct MFAFactorSchema {
83    /// Type of MFA factor (e.g., "totp")
84    factor_type: Option<String>,
85    /// User-friendly name for the factor
86    friendly_name: Option<String>,
87    /// Unique identifier for the factor
88    id: Option<Uuid>,
89    /// Verification status of the factor
90    status: Option<MFAFactorStatus>,
91}
92
93/// Status of a multi-factor authentication factor
94#[derive(Clone, Copy, Debug, Default, Deserialize, Serialize, Eq, PartialEq)]
95pub enum MFAFactorStatus {
96    /// Factor has been verified and is active
97    Verified,
98    /// Factor is not yet verified
99    #[default]
100    Unverified,
101}