#!/usr/bin/env bash
# Emergency access recovery: reset 2FA of a panel account (lost phone AND recovery codes).
# The user keeps the password and links a new authenticator at the next login.
#   sudo ./scripts/reset-2fa.sh            # list accounts
#   sudo ./scripts/reset-2fa.sh <username>
source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"
require_root
require_installed

if [[ -z ${1:-} ]]; then
  rspc_cli admin list-users
  echo
  echo "Usage: sudo $0 <username>"
  exit 0
fi
confirm "Reset 2FA for '$1' and sign them out everywhere?" || exit 0
rspc_cli admin reset-2fa "$1"
