Skip to main content

auth0_integration/models/
auth0_user.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Deserialize, Serialize)]
4pub struct Auth0User {
5    pub user_id: String,
6    pub email: String,
7    pub email_verified: bool,
8    pub name: Option<String>,
9    pub picture: Option<String>,
10}
11
12impl Auth0User {
13    /// Creates a new `Auth0User`.
14    ///
15    /// This struct is typically deserialized from Auth0 API responses, but
16    /// `new()` is provided for convenience in tests or manual construction.
17    ///
18    /// # Parameters
19    ///
20    /// | Parameter        | Type            | Description                                      |
21    /// |------------------|-----------------|--------------------------------------------------|
22    /// | `user_id`        | `String`        | Auth0 user ID (e.g. `"auth0|64a1b2c3d4e5f6"`)   |
23    /// | `email`          | `String`        | User's email address                             |
24    /// | `email_verified` | `bool`          | Whether the email has been verified              |
25    /// | `name`           | `Option<String>`| Full display name, if provided                   |
26    /// | `picture`        | `Option<String>`| URL of the user's profile picture, if provided   |
27    ///
28    /// # Example
29    ///
30    /// ```rust
31    /// use auth0_integration::models::Auth0User;
32    ///
33    /// let user = Auth0User::new(
34    ///     "auth0|64a1b2c3d4e5f6".to_string(),
35    ///     "jane@example.com".to_string(),
36    ///     true,
37    ///     Some("Jane Doe".to_string()),
38    ///     None,
39    /// );
40    /// ```
41    pub fn new(
42        user_id: String,
43        email: String,
44        email_verified: bool,
45        name: Option<String>,
46        picture: Option<String>,
47    ) -> Self {
48        Self { user_id, email, email_verified, name, picture }
49    }
50}