Creates a user in the profile organization.
(
cx: &ProfileContext,
CreateArgs { email, name }: CreateArgs<'_>,
)
| 34 | |
| 35 | /// Creates a user in the profile organization. |
| 36 | pub async fn create( |
| 37 | cx: &ProfileContext, |
| 38 | CreateArgs { email, name }: CreateArgs<'_>, |
| 39 | ) -> Result<(), Error> { |
| 40 | let loading_spinner = cx.output_formatter().loading_spinner("Creating user..."); |
| 41 | let roles = cx.admin_client().list_roles().await?; |
| 42 | let role_ids = roles.into_iter().map(|role| role.id).collect(); |
| 43 | |
| 44 | cx.admin_client() |
| 45 | .create_user(CreateUserRequest { |
| 46 | email: email.to_string(), |
| 47 | name: name.to_string(), |
| 48 | provider: "local".to_string(), |
| 49 | role_ids, |
| 50 | }) |
| 51 | .await?; |
| 52 | |
| 53 | loading_spinner.finish_with_message("User created."); |
| 54 | Ok(()) |
| 55 | } |
| 56 | |
| 57 | /// Lists all the users in the profile organization. |
| 58 | pub async fn list(cx: &ProfileContext) -> Result<(), Error> { |