filter_user

Function filter_user 

Source
pub fn filter_user(user: &User) -> FilteredUser
Expand description

Converts a User with sensitive data into a FilteredUser safe for API responses.

This function removes password hashes and other sensitive information before returning User data to clients. Always use this helper instead of directly serializing User objects. Used by all authentication endpoints to ensure passwords are never exposed.

§Arguments

  • user: Reference to the internal User struct containing password hash

§Returns

FilteredUser with only safe-to-share information:

  • id: User ID
  • first_name, last_name: User name
  • username: Login username
  • is_admin: Admin privilege flag

§Important

The password hash is explicitly NOT included in the output. This prevents accidental exposure of sensitive authentication data.

§Example

let user = get_user_from_db(1).await?;
let safe_user = filter_user(&user);  // Convert User to FilteredUser
// safe_user can be safely serialized and sent to client