#!/bin/bash

authAdapter_traefik_setPassword() {
    local user="$1" password="$2"
    user="${user:-${CFG_TRAEFIK_USER:-admin}}"
    [[ -z "$password" ]] && password=$(generateRandomPassword)

    updateConfigOption "CFG_TRAEFIK_USER" "$user"
    updateConfigOption "CFG_TRAEFIK_PASS" "$password"
    export CFG_TRAEFIK_USER="$user" CFG_TRAEFIK_PASS="$password"

    if declare -F traefikRegenerateProtectionAuth >/dev/null 2>&1; then
        traefikRegenerateProtectionAuth
    fi
    dockerComposeRestart traefik 2>/dev/null || true
    isSuccessful "Traefik dashboard login set. User: $user — Password: $password"
}
