Skip to main content

erase_user

Function erase_user 

Source
pub async fn erase_user(
    ex: &mut dyn Executor,
    user_id: &str,
) -> Result<(), Error>
Expand description

Deletes every row the tables Tablo ships hold for user_id, its PanelUser::user_id, on every panel, through ex: its sessions, its mailed links and pending sign-ins, its second factors and recovery codes, its column choices and its notifications. Call it where the app deletes an account, inside the same transaction, rather than deleting those tables by name: a table a later release ships joins it.

It reads a model only when ex’s schema registers it, so an app that registers the few its panel reads calls it as is. It leaves three things to the app:

  • the user record, an AdminUser row included, which is the app’s to delete;
  • the AuthThrottle counts, which hold a hash of the login and the address, never either in the clear, and end with their window;
  • what the app’s own tables and the audit log record of the user.

A page the user has open keeps what it shows; its next request is anonymous.

use toasty::Executor as _;

let mut tx = db.transaction().await?;
tablo_core::erase_user(&mut tx, user_id).await?;
// ... delete the app's own rows for the user, then the user.
tx.commit().await

§Errors

The driver’s error when a delete fails; the transaction then holds whatever ran before it.