#!/usr/bin/env bash
#
# Open an SSH tunnel that exposes the Mailpit web UI on localhost:8025.
# Then browse to http://localhost:8025 on your Mac to see all emails the
# auth service has sent (magic-link confirmation, password reset, etc.).
#
# Usage:
#   ./scripts/prod/tunnel-mailpit.sh
#   # then open http://localhost:8025 in your browser.

set -euo pipefail

here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${here}/config.sh"

local_port="${1:-8025}"

echo "tunnel: localhost:${local_port} → ${SSH_HOST}:localhost:8025"
echo "open http://localhost:${local_port} in your browser"
echo "press Ctrl+C to close"
# shellcheck disable=SC2086
exec ssh ${SSH_OPTS} -N -L "${local_port}:localhost:8025" "${SSH_HOST}"
