setup_initial_admin

Function setup_initial_admin 

Source
pub async fn setup_initial_admin(
    __arg0: State<Arc<AppState>>,
    __arg1: Json<UserCreateScheme>,
) -> Result<impl IntoResponse, (StatusCode, Json<Value>)>
Expand description

Creates the initial administrator account for a fresh system.

This function handles the one-time setup of the first admin User. It checks that no admin exists before allowing creation via database count. This endpoint is only functional when the system has no administrators. Once created, subsequent admin registrations must go through the normal create_user endpoint with proper authorization.

§Arguments

  • State(data): Application state containing AppState for database access
  • request: UserCreateScheme containing user creation details (first_name, last_name, username, password)

§Returns

  • 200 OK with success message if admin account created
  • 400 Bad Request if:
    • Admin already exists (checked via admin count)
    • Username or password is empty
  • 500 Internal Server Error if database insertion fails

§Security Note

The password is hashed using Argon2 with a random salt before storage.