firebase_admin/auth/users/model.rs
1//! Ergonomic, Rust-facing user types.
2//!
3//! These are distinct from the crate-internal wire-format DTOs used to talk
4//! to the Identity Toolkit REST API, so that the public API never exposes
5//! Google's REST field naming or shapes directly.
6
7use crate::auth::identity_toolkit::requests::AccountInfo;
8use serde_json::Map;
9
10/// A Firebase user record.
11#[derive(Debug, Clone)]
12pub struct UserRecord {
13 /// The user's unique Firebase id.
14 pub uid: String,
15 /// The user's email address, if set.
16 pub email: Option<String>,
17 /// Whether the user's email address has been verified.
18 pub email_verified: bool,
19 /// The user's display name, if set.
20 pub display_name: Option<String>,
21 /// Whether the user account is disabled.
22 pub disabled: bool,
23 /// Custom claims attached to this user via [`crate::auth::AuthClient`]
24 /// custom-claims operations.
25 pub custom_claims: Map<String, serde_json::Value>,
26}
27
28impl From<AccountInfo> for UserRecord {
29 fn from(info: AccountInfo) -> Self {
30 let custom_claims = info
31 .custom_attributes
32 .as_deref()
33 .and_then(|raw| serde_json::from_str(raw).ok())
34 .unwrap_or_default();
35
36 Self {
37 uid: info.local_id,
38 email: info.email,
39 email_verified: info.email_verified,
40 display_name: info.display_name,
41 disabled: info.disabled.unwrap_or(false),
42 custom_claims,
43 }
44 }
45}
46
47/// Fields accepted when creating a new user.
48#[derive(Debug, Default, Clone)]
49pub struct CreateUserRequest {
50 /// An explicit uid for the new user; if omitted, Firebase assigns one.
51 pub uid: Option<String>,
52 /// The new user's email address.
53 pub email: Option<String>,
54 /// The new user's initial password.
55 pub password: Option<String>,
56 /// The new user's display name.
57 pub display_name: Option<String>,
58 /// Whether the new user account should start disabled.
59 pub disabled: Option<bool>,
60}
61
62/// Fields accepted when updating an existing user. `None` fields are left
63/// unchanged.
64#[derive(Debug, Default, Clone)]
65pub struct UpdateUserRequest {
66 /// New email address.
67 pub email: Option<String>,
68 /// New display name.
69 pub display_name: Option<String>,
70 /// New disabled state.
71 pub disabled: Option<bool>,
72 /// Replaces the user's custom claims entirely, when set.
73 pub custom_claims: Option<Map<String, serde_json::Value>>,
74}