Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ jobs:
profile: minimal
toolchain: stable
override: true
- run: rustup component add rustfmt
- uses: actions-rs/cargo@v1
with:
command: check
Expand All @@ -52,6 +53,7 @@ jobs:
toolchain: stable
override: true
- run: rustup component add clippy
- run: rustup component add rustfmt
- uses: actions-rs/cargo@v1
with:
command: clippy
Expand All @@ -67,6 +69,7 @@ jobs:
profile: minimal
toolchain: stable
override: true
- run: rustup component add rustfmt
- name: Run tests
env:
FIREBASE_PROJECT_ID: ${{ secrets.FIREBASE_PROJECT_ID }}
Expand Down
38 changes: 38 additions & 0 deletions src/auth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,44 @@ impl FirebaseAuthClient {
/// # Ok(())
/// # }
/// ```
///
/// Disable a user:
///
/// ```
/// # #[tokio::main]
/// # async fn main() -> Result<(), fireplace::error::FirebaseError> {
/// # let auth_client = fireplace::auth::test_helpers::initialise()?;
/// use fireplace::auth::models::{NewUser, UpdateUserValues};
/// use ulid::Ulid;
///
/// let user_id = auth_client
/// .create_user(NewUser {
/// display_name: Some("Test User".to_string()),
/// email: format!("{}@example.com", Ulid::new()),
/// password: Ulid::new().to_string(),
/// })
/// .await?;
///
/// // Disable the user
/// auth_client
/// .update_user(&user_id, UpdateUserValues::new().disabled(true))
/// .await?;
///
/// // Verify the user is disabled
/// let user = auth_client.get_user(&user_id).await?.unwrap();
/// assert_eq!(user.disabled, Some(true));
///
/// // Re-enable the user
/// auth_client
/// .update_user(&user_id, UpdateUserValues::new().disabled(false))
/// .await?;
///
/// // Verify the user is enabled again
/// let user = auth_client.get_user(&user_id).await?.unwrap();
/// assert_eq!(user.disabled, Some(false));
/// # Ok(())
/// # }
/// ```
Comment thread
avborup marked this conversation as resolved.
#[tracing::instrument(name = "Update user", skip_all, fields(user_id = %user_id.as_ref()))]
pub async fn update_user(
&self,
Expand Down
14 changes: 14 additions & 0 deletions src/auth/models/update_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pub struct UpdateUserValues {
display_name: Option<Option<String>>,
email: Option<String>,
password: Option<String>,
disabled: Option<bool>,
}

impl UpdateUserValues {
Expand All @@ -31,6 +32,12 @@ impl UpdateUserValues {
self.password = Some(password.into());
self
}

/// Enable or disable the user.
pub fn disabled(mut self, disabled: bool) -> Self {
self.disabled = Some(disabled);
self
}
}

#[derive(Serialize)]
Expand All @@ -45,6 +52,8 @@ pub(crate) struct UpdateUserBody<'a> {
password: Option<String>,
#[serde(skip_serializing_if = "Vec::is_empty")]
delete_attribute: Vec<&'static str>,
#[serde(skip_serializing_if = "Option::is_none")]
disable_user: Option<bool>,
}

impl<'a> UpdateUserBody<'a> {
Expand All @@ -63,6 +72,11 @@ impl<'a> UpdateUserBody<'a> {
email: values.email,
password: values.password,
delete_attribute,
// The `disabled` field is internally renamed to `disableUser`. See the Firebase Node
// Admin SDK implementation for reference:
// - https://github.com/firebase/firebase-admin-node/blob/137a0d9312b0b45b69f6a5111081420729d8eaeb/src/auth/auth-api-request.ts#L480-L486
// - https://github.com/firebase/firebase-admin-node/blob/137a0d9312b0b45b69f6a5111081420729d8eaeb/src/auth/auth-api-request.ts#L1468-L1472
disable_user: values.disabled,
}
}
}
Loading