export function decodeBase64(base64: string): string {
  try {
    // Browser
    if (typeof window !== "undefined" && typeof window.atob === "function") {
      const binary = window.atob(base64)

      // Support Unicode
      const bytes = Uint8Array.from(binary, c => c.charCodeAt(0))

      return new TextDecoder().decode(bytes)
    }

    // Node / SSR
    if (typeof Buffer !== "undefined") {
      return Buffer.from(base64, "base64").toString("utf-8")
    }

    throw new Error("No base64 decoder available")
  } catch {
    throw new Error("Invalid base64 string")
  }
}
