flip_api.user_services.delete_user

Attributes

router

Functions

delete_user(, token_id, Any])

Delete a user from Cognito and revoke their role grants.

Module Contents

flip_api.user_services.delete_user.router
flip_api.user_services.delete_user.delete_user(user_id: uuid.UUID, request: fastapi.Request, db: sqlmodel.Session = Depends(get_session), token_id: uuid.UUID = Depends(verify_token)) dict[str, Any]

Delete a user from Cognito and revoke their role grants.

DB cleanup (delete role grants + write audit row) commits before the Cognito delete so a Cognito failure leaves a Cognito user with no app-side authority — preferable to dangling role grants on a deleted user. Idempotent: if the Cognito user is already gone, the DB-side cleanup still runs so any ghost role grants are reaped.

Parameters:
  • user_id (UUID) – Cognito sub of the user to delete. FastAPI validates the path segment, returning 422 on malformed input.

  • request (Request) – The FastAPI request object.

  • db (Session) – The database session.

  • token_id (UUID) – ID of the authenticated user performing the delete.

Returns:

Empty dictionary on success.

Return type:

dict[str, Any]

Raises:

HTTPException – If the caller lacks permission or an unexpected error (other than a Cognito 404) occurs.