Skip to main content

reauth_types/
responses.rs

1use serde::{Deserialize, Serialize};
2
3/// User details returned by the Developer API.
4///
5/// Contains full user information that isn't available in JWT claims.
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct UserDetails {
8    /// User ID
9    pub id: String,
10
11    /// User's email address
12    pub email: String,
13
14    /// User's roles
15    pub roles: Vec<String>,
16
17    /// When the email was verified (ISO 8601 format)
18    pub email_verified_at: Option<String>,
19
20    /// When the user last logged in (ISO 8601 format)
21    pub last_login_at: Option<String>,
22
23    /// Whether the user account is frozen
24    pub is_frozen: bool,
25
26    /// Whether the user is on the waitlist whitelist
27    pub is_whitelisted: bool,
28
29    /// When the user account was created (ISO 8601 format)
30    pub created_at: Option<String>,
31}
32
33#[cfg(test)]
34mod tests {
35    use super::*;
36
37    #[test]
38    fn test_user_details_serde() {
39        let user = UserDetails {
40            id: "user123".to_string(),
41            email: "test@example.com".to_string(),
42            roles: vec!["user".to_string(), "admin".to_string()],
43            email_verified_at: Some("2024-01-15T10:30:00Z".to_string()),
44            last_login_at: Some("2024-01-20T14:00:00Z".to_string()),
45            is_frozen: false,
46            is_whitelisted: true,
47            created_at: Some("2024-01-01T00:00:00Z".to_string()),
48        };
49
50        let json = serde_json::to_string(&user).unwrap();
51        let parsed: UserDetails = serde_json::from_str(&json).unwrap();
52
53        assert_eq!(parsed.id, "user123");
54        assert_eq!(parsed.email, "test@example.com");
55        assert!(!parsed.is_frozen);
56        assert!(parsed.is_whitelisted);
57    }
58}