Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(dashboard): stop the proxy modal from clearing what it cannot read

Yudhi Armyndharis2ab41ea97ad7
diff --git a/dashboard/src/hooks/useSessionCreateForm.ts b/dashboard/src/hooks/useSessionCreateForm.ts
index 585011a73..859571dcd 100644
--- a/dashboard/src/hooks/useSessionCreateForm.ts
+++ b/dashboard/src/hooks/useSessionCreateForm.ts
@@ -1,6 +1,7 @@
-import { useState } from 'react';
+import { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
-import { sessionApi, type Session, type SessionProxyType } from '../services/api';
+import { sessionApi, type Session } from '../services/api';
+import { isValidProxyUrl } from '../utils/sessionForm';
import { useToast } from './useToast';
export interface UseSessionCreateFormArgs {
@@ -17,8 +18,6 @@ export interface SessionCreateForm {
setUseProxy: (enabled: boolean) => void;
proxyUrl: string;
setProxyUrl: (url: string) => void;
- proxyType: SessionProxyType;
- setProxyType: (type: SessionProxyType) => void;
creating: boolean;
handleCreate: () => Promise<void>;
}
@@ -37,22 +36,30 @@ export function useSessionCreateForm({ onCreated, onFailed }: UseSessionCreateFo
const [newSessionName, setNewSessionName] = useState('');
const [useProxy, setUseProxy] = useState(false);
const [proxyUrl, setProxyUrl] = useState('');
- const [proxyType, setProxyType] = useState<SessionProxyType>('http');
const [creating, setCreating] = useState(false);
const resetProxyFields = () => {
setUseProxy(false);
setProxyUrl('');
- setProxyType('http');
};
+ // Anything typed into the proxy fields is dropped when the modal closes, however it closes. A
+ // cancelled create otherwise leaves a credentialed URL in memory for the life of the page, and
+ // prefills it the next time the modal opens.
+ useEffect(() => {
+ if (!showCreateModal) resetProxyFields();
+ }, [showCreateModal]);
+
const handleCreate = async () => {
if (!newSessionName.trim()) return;
+ // Guarded here rather than only on the Create button: the name field's Enter key calls this
+ // directly, so a button-only check creates a session with no proxy while the toggle says on.
+ if (useProxy && !isValidProxyUrl(proxyUrl.trim())) return;
try {
setCreating(true);
const newSession = await sessionApi.create(
newSessionName,
- useProxy && proxyUrl.trim() ? { proxyUrl: proxyUrl.trim(), proxyType } : undefined,
+ useProxy && proxyUrl.trim() ? { proxyUrl: proxyUrl.trim() } : undefined,
);
setNewSessionName('');
resetProxyFields();
@@ -77,8 +84,6 @@ export function useSessionCreateForm({ onCreated, onFailed }: UseSessionCreateFo
setUseProxy,
proxyUrl,
setProxyUrl,
- proxyType,
- setProxyType,
creating,
handleCreate,
};
diff --git a/dashboard/src/i18n/locales/ar.json b/dashboard/src/i18n/locales/ar.json
index 3e342a0a0..0e5ece0c0 100644
--- a/dashboard/src/i18n/locales/ar.json
+++ b/dashboard/src/i18n/locales/ar.json
@@ -217,9 +217,6 @@
"phone": "رقم الهاتف",
"status": "الحالة",
"lastActive": "آخر نشاط",
- "proxy": "Proxy",
- "proxyEnabled": "{{type}} · {{host}}",
- "proxyDisabled": "None",
"actions": "إجراءات"
},
"noSessions": "لم يتم العثور على جلسات. أنشئ جلسة للبدء.",
@@ -325,7 +322,6 @@
"url": "Proxy URL",
"urlPlaceholder": "http://user:[email protected]:8080",
"urlKeepPlaceholder": "Enter new URL to replace {{host}} (credentials not shown)",
- "type": "Proxy type",
"configured": "{{host}} ({{type}})",
"noProxy": "No proxy configured",
"hasCredentials": "Credentials are stored but not shown. Enter a full URL to change them.",
@@ -925,7 +921,7 @@
"title": "المثيلات",
"description": "أنشئ مثيلات لكل حساب لهذا التكامل. كل مثيل له مفتاح توقيع سري وعنوان دخول خاص به.",
"create": "إنشاء مثيل",
- "save": "Save",
+ "save": "Save",
"empty": "لا توجد مثيلات بعد. أنشئ مثيلًا للحصول على عنوان دخول ومفتاح سري.",
"loadError": "فشل تحميل المثيلات.",
"allSessions": "جميع الجلسات",
diff --git a/dashboard/src/i18n/locales/de.json b/dashboard/src/i18n/locales/de.json
index ce65c2591..a0d9e2ae1 100644
--- a/dashboard/src/i18n/locales/de.json
+++ b/dashboard/src/i18n/locales/de.json
@@ -206,9 +206,6 @@
"phone": "Telefonnummer",
"status": "Status",
"lastActive": "Zuletzt aktiv",
- "proxy": "Proxy",
- "proxyEnabled": "{{type}} · {{host}}",
- "proxyDisabled": "None",
"actions": "Aktionen"
},
"noSessions": "Keine Sitzungen gefunden. Erstelle eine, um zu beginnen.",
@@ -314,7 +311,6 @@
"url": "Proxy URL",
"urlPlaceholder": "http://user:[email protected]:8080",
"urlKeepPlaceholder": "Enter new URL to replace {{host}} (credentials not shown)",
- "type": "Proxy type",
"configured": "{{host}} ({{type}})",
"noProxy": "No proxy configured",
"hasCredentials": "Credentials are stored but not shown. Enter a full URL to change them.",
@@ -910,7 +906,7 @@
"title": "Instanzen",
"description": "Erstelle kontobezogene Instanzen für diese Integration. Jede Instanz besitzt ein eigenes Signaturgeheimnis und eine eigene Ingress-URL.",
"create": "Instanz erstellen",
- "save": "Save",
+ "save": "Save",
"empty": "Noch keine Instanzen vorhanden. Erstelle eine, um eine Ingress-URL und ein Geheimnis zu erhalten.",
"loadError": "Instanzen konnten nicht geladen werden.",
"allSessions": "Alle Sitzungen",
diff --git a/dashboard/src/i18n/locales/en.json b/dashboard/src/i18n/locales/en.json
index 61e3e8fe8..874665247 100644
--- a/dashboard/src/i18n/locales/en.json
+++ b/dashboard/src/i18n/locales/en.json
@@ -315,7 +315,6 @@
"url": "Proxy URL",
"urlPlaceholder": "http://user:[email protected]:8080",
"urlKeepPlaceholder": "Enter new URL to replace {{host}} (credentials not shown)",
- "type": "Proxy type",
"configured": "{{host}} ({{type}})",
"noProxy": "No proxy configured",
"hasCredentials": "Credentials are stored but not shown. Enter a full URL to change them.",
@@ -350,9 +349,6 @@
"phone": "Phone",
"sessionId": "Session ID",
"lastActive": "Last Active",
- "proxy": "Proxy",
- "proxyEnabled": "{{type}} · {{host}}",
- "proxyDisabled": "None",
"error": "Error",
"restriction": "Restriction"
},
diff --git a/dashboard/src/i18n/locales/es.json b/dashboard/src/i18n/locales/es.json
index e510223f8..b569af54d 100644
--- a/dashboard/src/i18n/locales/es.json
+++ b/dashboard/src/i18n/locales/es.json
@@ -206,9 +206,6 @@
"phone": "Número de teléfono",
"status": "Estado",
"lastActive": "Última actividad",
- "proxy": "Proxy",
- "proxyEnabled": "{{type}} · {{host}}",
- "proxyDisabled": "None",
"actions": "Acciones"
},
"noSessions": "No se encontraron sesiones. Crea una para empezar.",
@@ -314,7 +311,6 @@
"url": "Proxy URL",
"urlPlaceholder": "http://user:[email protected]:8080",
"urlKeepPlaceholder": "Enter new URL to replace {{host}} (credentials not shown)",
- "type": "Proxy type",
"configured": "{{host}} ({{type}})",
"noProxy": "No proxy configured",
"hasCredentials": "Credentials are stored but not shown. Enter a full URL to change them.",
@@ -910,7 +906,7 @@
"title": "Instancias",
"description": "Aprovisiona instancias por cuenta para esta integración. Cada instancia tiene su propio secreto de firma y URL de entrada.",
"create": "Crear instancia",
- "save": "Save",
+ "save": "Save",
"empty": "Aún no hay instancias. Crea una para obtener una URL de entrada y un secreto.",
"loadError": "Error al cargar las instancias.",
"allSessions": "Todas las sesiones",
diff --git a/dashboard/src/i18n/locales/fr.json b/dashboard/src/i18n/locales/fr.json
index 99a06f64b..db4ea7e9d 100644
--- a/dashboard/src/i18n/locales/fr.json
+++ b/dashboard/src/i18n/locales/fr.json
@@ -206,9 +206,6 @@
"phone": "Numéro de téléphone",
"status": "Statut",
"lastActive": "Dernière activité",
- "proxy": "Proxy",
- "proxyEnabled": "{{type}} · {{host}}",
- "proxyDisabled": "None",
"actions": "Actions"
},
"noSessions": "Aucune session trouvée. Créez-en une pour commencer.",
@@ -314,7 +311,6 @@
"url": "Proxy URL",
"urlPlaceholder": "http://user:[email protected]:8080",
"urlKeepPlaceholder": "Enter new URL to replace {{host}} (credentials not shown)",
- "type": "Proxy type",
"configured": "{{host}} ({{type}})",
"noProxy": "No proxy configured",
"hasCredentials": "Credentials are stored but not shown. Enter a full URL to change them.",
@@ -910,7 +906,7 @@
"title": "Instances",
"description": "Provisionnez des instances par compte pour cette intégration. Chaque instance dispose de son propre secret de signature et de sa propre URL d'entrée.",
"create": "Créer une instance",
- "save": "Save",
+ "save": "Save",
"empty": "Aucune instance pour le moment. Créez-en une pour obtenir une URL d'entrée et un secret.",
"loadError": "Échec du chargement des instances.",
"allSessions": "Toutes les sessions",
diff --git a/dashboard/src/i18n/locales/he.json b/dashboard/src/i18n/locales/he.json
index 15c360dff..3f56eba77 100644
--- a/dashboard/src/i18n/locales/he.json
+++ b/dashboard/src/i18n/locales/he.json
@@ -213,9 +213,6 @@
"phone": "מספר טלפון",
"status": "סטטוס",
"lastActive": "פעילות אחרונה",
- "proxy": "Proxy",
- "proxyEnabled": "{{type}} · {{host}}",
- "proxyDisabled": "None",
"actions": "פעולות"
},
"noSessions": "לא נמצאו Sessions. יש ליצור אחד כדי להתחיל.",
@@ -321,7 +318,6 @@
"url": "Proxy URL",
"urlPlaceholder": "http://user:[email protected]:8080",
"urlKeepPlaceholder": "Enter new URL to replace {{host}} (credentials not shown)",
- "type": "Proxy type",
"configured": "{{host}} ({{type}})",
"noProxy": "No proxy configured",
"hasCredentials": "Credentials are stored but not shown. Enter a full URL to change them.",
@@ -919,7 +915,7 @@
"title": "מופעים",
"description": "הקצו מופעים לכל חשבון עבור אינטגרציה זו. לכל מופע יש מפתח חתימה סודי וכתובת URL לקליטה משלו.",
"create": "יצירת מופע",
- "save": "Save",
+ "save": "Save",
"empty": "אין עדיין מופעים. צרו מופע כדי לקבל כתובת URL וסוד.",
"loadError": "טעינת המופעים נכשלה.",
"allSessions": "כל ה-Sessions",
diff --git a/dashboard/src/i18n/locales/it.json b/dashboard/src/i18n/locales/it.json
index 8311866cf..4ee6ec715 100644
--- a/dashboard/src/i18n/locales/it.json
+++ b/dashboard/src/i18n/locales/it.json
@@ -206,9 +206,6 @@
"phone": "Numero di Telefono",
"status": "Stato",
"lastActive": "Ultima Attività",
- "proxy": "Proxy",
- "proxyEnabled": "{{type}} · {{host}}",
- "proxyDisabled": "None",
"actions": "Azioni"
},
"noSessions": "Nessuna sessione trovata. Creane una per iniziare.",
@@ -314,7 +311,6 @@
"url": "Proxy URL",
"urlPlaceholder": "http://user:[email protected]:8080",
"urlKeepPlaceholder": "Enter new URL to replace {{host}} (credentials not shown)",
- "type": "Proxy type",
"configured": "{{host}} ({{type}})",
"noProxy": "No proxy configured",
"hasCredentials": "Credentials are stored but not shown. Enter a full URL to change them.",
@@ -910,7 +906,7 @@
"title": "Istanze",
"description": "Effettua il provisioning di istanze per account per questa integrazione. Ogni istanza ha il proprio segreto di firma e URL di ingresso.",
"create": "Crea istanza",
- "save": "Save",
+ "save": "Save",
"empty": "Nessuna istanza ancora. Creane una per ottenere un URL di ingresso e un segreto.",
"loadError": "Impossibile caricare le istanze.",
"allSessions": "Tutte le sessioni",
diff --git a/dashboard/src/i18n/locales/ko.json b/dashboard/src/i18n/locales/ko.json
index f5f729719..76ef6ed6d 100644
--- a/dashboard/src/i18n/locales/ko.json
+++ b/dashboard/src/i18n/locales/ko.json
@@ -206,9 +206,6 @@
"phone": "전화번호",
"status": "상태",
"lastActive": "마지막 활동",
- "proxy": "Proxy",
- "proxyEnabled": "{{type}} · {{host}}",
- "proxyDisabled": "None",
"actions": "작업"
},
"noSessions": "세션이 없습니다. 세션을 생성해 시작하세요.",
@@ -314,7 +311,6 @@
"url": "Proxy URL",
"urlPlaceholder": "http://user:[email protected]:8080",
"urlKeepPlaceholder": "Enter new URL to replace {{host}} (credentials not shown)",
- "type": "Proxy type",
"configured": "{{host}} ({{type}})",
"noProxy": "No proxy configured",
"hasCredentials": "Credentials are stored but not shown. Enter a full URL to change them.",
@@ -910,7 +906,7 @@
"title": "인스턴스",
"description": "이 연동을 위해 계정별 인스턴스를 프로비저닝하세요. 각 인스턴스는 고유한 서명 시크릿과 인그레스 URL을 가집니다.",
"create": "인스턴스 생성",
- "save": "Save",
+ "save": "Save",
"empty": "아직 인스턴스가 없습니다. 인스턴스를 만들면 인그레스 URL과 시크릿을 받을 수 있습니다.",
"loadError": "인스턴스를 불러오지 못했습니다.",
"allSessions": "모든 세션",
diff --git a/dashboard/src/i18n/locales/pt-BR.json b/dashboard/src/i18n/locales/pt-BR.json
index d2473dcde..c91ee41d7 100644
--- a/dashboard/src/i18n/locales/pt-BR.json
+++ b/dashboard/src/i18n/locales/pt-BR.json
@@ -206,9 +206,6 @@
"phone": "Número de telefone",
"status": "Status",
"lastActive": "Última atividade",
- "proxy": "Proxy",
- "proxyEnabled": "{{type}} · {{host}}",
- "proxyDisabled": "None",
"actions": "Ações"
},
"noSessions": "Nenhuma sessão encontrada. Crie uma para começar.",
@@ -314,7 +311,6 @@
"url": "Proxy URL",
"urlPlaceholder": "http://user:[email protected]:8080",
"urlKeepPlaceholder": "Enter new URL to replace {{host}} (credentials not shown)",
- "type": "Proxy type",
"configured": "{{host}} ({{type}})",
"noProxy": "No proxy configured",
"hasCredentials": "Credentials are stored but not shown. Enter a full URL to change them.",
@@ -910,7 +906,7 @@
"title": "Instâncias",
"description": "Provisione instâncias por conta para esta integração. Cada instância tem seu próprio segredo de assinatura e URL de entrada.",
"create": "Criar instância",
- "save": "Save",
+ "save": "Save",
"empty": "Ainda não há instâncias. Crie uma para obter uma URL de entrada e um segredo.",
"loadError": "Falha ao carregar as instâncias.",
"allSessions": "Todas as sessões",
diff --git a/dashboard/src/i18n/locales/te.json b/dashboard/src/i18n/locales/te.json
index d0d3b12c3..22264b277 100644
--- a/dashboard/src/i18n/locales/te.json
+++ b/dashboard/src/i18n/locales/te.json
@@ -206,9 +206,6 @@
"phone": "ఫోన్ నంబర్",
"status": "స్థితి",
"lastActive": "చివరిసారి యాక్టివ్",
- "proxy": "Proxy",
- "proxyEnabled": "{{type}} · {{host}}",
- "proxyDisabled": "None",
"actions": "చర్యలు"
},
"noSessions": "ఎలాంటి సెషన్లు కనుగొనబడలేదు. ప్రారంభించడానికి ఒకదాన్ని సృష్టించండి.",
@@ -314,7 +311,6 @@
"url": "Proxy URL",
"urlPlaceholder": "http://user:[email protected]:8080",
"urlKeepPlaceholder": "Enter new URL to replace {{host}} (credentials not shown)",
- "type": "Proxy type",
"configured": "{{host}} ({{type}})",
"noProxy": "No proxy configured",
"hasCredentials": "Credentials are stored but not shown. Enter a full URL to change them.",
@@ -910,7 +906,7 @@
"title": "ఇన్‌స్టాన్స్‌లు",
"description": "ఈ ఇంటిగ్రేషన్ కోసం ఖాతా వారీగా ఇన్‌స్టాన్స్‌లను ప్రొవిజన్ చేయండి. ప్రతి ఇన్‌స్టాన్స్‌కు దాని స్వంత సైనింగ్ సీక్రెట్ మరియు ఇన్‌గ్రెస్ URL ఉంటుంది.",
"create": "ఇన్‌స్టాన్స్‌ను సృష్టించండి",
- "save": "Save",
+ "save": "Save",
"empty": "ఇంకా ఇన్‌స్టాన్స్‌లు లేవు. ఇన్‌గ్రెస్ URL మరియు సీక్రెట్ పొందడానికి ఒకటి సృష్టించండి.",
"loadError": "ఇన్‌స్టాన్స్‌లను లోడ్ చేయడం విఫలమైంది.",
"allSessions": "అన్ని సెషన్‌లు",
diff --git a/dashboard/src/i18n/locales/tr.json b/dashboard/src/i18n/locales/tr.json
index 5a5ac2fae..645c11ecc 100644
--- a/dashboard/src/i18n/locales/tr.json
+++ b/dashboard/src/i18n/locales/tr.json
@@ -206,9 +206,6 @@
"phone": "Telefon Numarası",
"status": "Durum",
"lastActive": "Son Görülme",
- "proxy": "Proxy",
- "proxyEnabled": "{{type}} · {{host}}",
- "proxyDisabled": "None",
"actions": "İşlemler"
},
"noSessions": "Oturum bulunamadı. Başlamak için bir tane oluşturun.",
@@ -318,7 +315,6 @@
"url": "Proxy URL",
"urlPlaceholder": "http://user:[email protected]:8080",
"urlKeepPlaceholder": "Enter new URL to replace {{host}} (credentials not shown)",
- "type": "Proxy type",
"configured": "{{host}} ({{type}})",
"noProxy": "No proxy configured",
"hasCredentials": "Credentials are stored but not shown. Enter a full URL to change them.",
@@ -910,7 +906,7 @@
"title": "Örnekler (Instances)",
"description": "Bu entegrasyon için hesap başına örnekler tanımlayın. Her örneğin kendi imzalama gizli anahtarı ve giriş URL'si vardır.",
"create": "Örnek oluştur",
- "save": "Save",
+ "save": "Save",
"empty": "Henüz örnek yok. Giriş URL'si ve gizli anahtar almak için bir tane oluşturun.",
"loadError": "Örnekler yüklenemedi.",
"allSessions": "Tüm oturumlar",
diff --git a/dashboard/src/i18n/locales/zh-CN.json b/dashboard/src/i18n/locales/zh-CN.json
index f62a5ad08..fc5f97bd1 100644
--- a/dashboard/src/i18n/locales/zh-CN.json
+++ b/dashboard/src/i18n/locales/zh-CN.json
@@ -206,9 +206,6 @@
"phone": "电话号码",
"status": "状态",
"lastActive": "上次活跃",
- "proxy": "Proxy",
- "proxyEnabled": "{{type}} · {{host}}",
- "proxyDisabled": "None",
"actions": "操作"
},
"noSessions": "未找到会话。创建一个即可开始。",
@@ -314,7 +311,6 @@
"url": "Proxy URL",
"urlPlaceholder": "http://user:[email protected]:8080",
"urlKeepPlaceholder": "Enter new URL to replace {{host}} (credentials not shown)",
- "type": "Proxy type",
"configured": "{{host}} ({{type}})",
"noProxy": "No proxy configured",
"hasCredentials": "Credentials are stored but not shown. Enter a full URL to change them.",
@@ -910,7 +906,7 @@
"title": "实例",
"description": "为此集成按账户配置实例。每个实例都有自己的签名密钥和接入 URL。",
"create": "创建实例",
- "save": "Save",
+ "save": "Save",
"empty": "暂无实例。创建一个以获取接入 URL 和密钥。",
"loadError": "加载实例失败。",
"allSessions": "所有会话",
diff --git a/dashboard/src/i18n/locales/zh-HK.json b/dashboard/src/i18n/locales/zh-HK.json
index ee464eafd..65a7fe95a 100644
--- a/dashboard/src/i18n/locales/zh-HK.json
+++ b/dashboard/src/i18n/locales/zh-HK.json
@@ -206,9 +206,6 @@
"phone": "電話號碼",
"status": "狀態",
"lastActive": "上次活躍",
- "proxy": "Proxy",
- "proxyEnabled": "{{type}} · {{host}}",
- "proxyDisabled": "None",
"actions": "操作"
},
"noSessions": "找不到工作階段。建立一個即可開始。",
@@ -314,7 +311,6 @@
"url": "Proxy URL",
"urlPlaceholder": "http://user:[email protected]:8080",
"urlKeepPlaceholder": "Enter new URL to replace {{host}} (credentials not shown)",
- "type": "Proxy type",
"configured": "{{host}} ({{type}})",
"noProxy": "No proxy configured",
"hasCredentials": "Credentials are stored but not shown. Enter a full URL to change them.",
@@ -910,7 +906,7 @@
"title": "執行個體",
"description": "為此整合按帳戶佈建執行個體。每個執行個體都有專屬的簽署密鑰和連入 URL。",
"create": "建立執行個體",
- "save": "Save",
+ "save": "Save",
"empty": "尚無執行個體。建立一個即可取得連入 URL 和密鑰。",
"loadError": "載入執行個體失敗。",
"allSessions": "所有工作階段",
diff --git a/dashboard/src/pages/Sessions.css b/dashboard/src/pages/Sessions.css
index fc1a556e5..ace39b55b 100644
--- a/dashboard/src/pages/Sessions.css
+++ b/dashboard/src/pages/Sessions.css
@@ -86,12 +86,6 @@
margin-bottom: 1.25rem;
}
-.sessions-page .session-card .session-proxy {
- margin: -0.75rem 0 1rem;
- padding-bottom: 0.75rem;
- border-bottom: 1px solid var(--border);
-}
-
.sessions-page .card-header h3 {
/* Inherits from H3 */
margin: 0;
diff --git a/dashboard/src/pages/Sessions.test.ts b/dashboard/src/pages/Sessions.test.ts
index b34a7a574..146207d55 100644
--- a/dashboard/src/pages/Sessions.test.ts
+++ b/dashboard/src/pages/Sessions.test.ts
@@ -79,6 +79,7 @@ const fetchCalls: FetchCall[] = [];
function resetFetchCalls(): void {
fetchCalls.length = 0;
sessionProxy = { enabled: false, proxyType: null, proxyHost: null, hasCredentials: false };
+ proxyGetFails = false;
}
function findFetchCall(method: string, path: string): FetchCall | undefined {
@@ -92,6 +93,7 @@ function findFetchCall(method: string, path: string): FetchCall | undefined {
// Mutable so a test can set the starting value and observe what a PATCH wrote back.
let sessionConfig = { autoRejectCalls: false, maxReconnectAttempts: null as number | null, reconnectBaseDelay: 5000 };
let configPatchFails = false;
+let proxyGetFails = false;
let sessionProxy = {
enabled: false,
proxyType: null as string | null,
@@ -156,6 +158,7 @@ function installFetchStub(): void {
const proxyMatch = path.match(/^\/api\/sessions\/([^/]+)\/proxy$/);
if (proxyMatch) {
+ if (method === 'GET' && proxyGetFails) return Promise.resolve(jsonResponse({ message: 'boom' }, 500));
if (method === 'GET') return Promise.resolve(jsonResponse({ ...sessionProxy }));
if (method === 'PATCH') {
const payload = body as { proxyUrl?: string | null } | undefined;
@@ -470,3 +473,48 @@ test('a rejected write reverts the toggle instead of leaving it showing a state
await rtl.waitFor(() => assert.equal((rtl.screen.getByRole('checkbox') as HTMLInputElement).checked, false));
configPatchFails = false;
});
+
+test('a failed proxy read offers no Save, so it cannot clear a proxy nobody could see', async () => {
+ const { screen, fireEvent, within, waitFor } = rtl;
+ resetFetchCalls();
+ // The session HAS a proxy, with credentials the API deliberately never returns. Reading it fails.
+ sessionProxy = { enabled: true, proxyType: 'socks5', proxyHost: 'proxy.internal:1080', hasCredentials: true };
+ proxyGetFails = true;
+ renderSessions();
+
+ await screen.findByText('new-device');
+ const qrCard = screen.getByText('new-device').closest('.session-card') as HTMLElement;
+ fireEvent.click(within(qrCard).getByRole('button', { name: 'Proxy' }));
+
+ const dialog = await screen.findByRole('dialog');
+ await waitFor(() => assert.ok(findFetchCall('GET', '/api/sessions/sess-qr-1/proxy')));
+
+ // No editable form and no Save: an "off" toggle here would read as "no proxy configured", and
+ // saving from that state sends proxyUrl:null, destroying the stored URL and its credentials.
+ await waitFor(() => assert.equal(within(dialog).queryByRole('button', { name: 'Save' }), null));
+ assert.equal(within(dialog).queryByRole('checkbox'), null);
+ assert.equal(findFetchCall('PATCH', '/api/sessions/sess-qr-1/proxy'), undefined);
+});
+
+test('saving without retyping the URL leaves the stored proxy and its credentials alone', async () => {
+ const { screen, fireEvent, within, waitFor } = rtl;
+ resetFetchCalls();
+ sessionProxy = { enabled: true, proxyType: 'http', proxyHost: 'proxy.internal:8080', hasCredentials: true };
+ renderSessions();
+
+ await screen.findByText('new-device');
+ const qrCard = screen.getByText('new-device').closest('.session-card') as HTMLElement;
+ fireEvent.click(within(qrCard).getByRole('button', { name: 'Proxy' }));
+
+ const dialog = await screen.findByRole('dialog');
+ await waitFor(() => assert.ok(findFetchCall('GET', '/api/sessions/sess-qr-1/proxy')));
+ // The URL field is deliberately empty: credentials are never sent back to render.
+ fireEvent.click(within(dialog).getByRole('button', { name: 'Save' }));
+
+ await waitFor(() => assert.equal(screen.queryByRole('dialog'), null));
+ assert.equal(
+ findFetchCall('PATCH', '/api/sessions/sess-qr-1/proxy'),
+ undefined,
+ 'an untouched form must not write, or it would replace a credentialed URL with nothing',
+ );
+});
diff --git a/dashboard/src/pages/Sessions.tsx b/dashboard/src/pages/Sessions.tsx
index 5aedafac5..65177ba9f 100644
--- a/dashboard/src/pages/Sessions.tsx
+++ b/dashboard/src/pages/Sessions.tsx
@@ -21,7 +21,6 @@ import {
type Session,
type SessionConfig,
type SessionProxy,
- type SessionProxyType,
type AccountRestriction,
} from '../services/api';
import { queryKeys } from '../hooks/queries';
@@ -65,13 +64,6 @@ function restrictionTitle(restriction: AccountRestriction, t: TFunction): string
return parts.join(' · ');
}
-const PROXY_TYPE_OPTIONS: { value: SessionProxyType; label: string }[] = [
- { value: 'http', label: 'HTTP' },
- { value: 'https', label: 'HTTPS' },
- { value: 'socks4', label: 'SOCKS4' },
- { value: 'socks5', label: 'SOCKS5' },
-];
-
export function Sessions() {
const { t } = useTranslation();
useDocumentTitle(t('sessions.title'));
@@ -101,6 +93,9 @@ export function Sessions() {
const [proxyEnabled, setProxyEnabled] = useState(false);
const [proxyUrl, setProxyUrl] = useState('');
const [proxyUrlError, setProxyUrlError] = useState<string | null>(null);
+ // A failed read must not look like "no proxy configured": saving from that state would clear a
+ // proxy, and the credentials with it, that the operator never got to see.
+ const [proxyLoadFailed, setProxyLoadFailed] = useState(false);
const fetchSessions = useCallback(async (): Promise<Session[]> => {
try {
@@ -162,8 +157,6 @@ export function Sessions() {
setUseProxy,
proxyUrl: createProxyUrl,
setProxyUrl: setCreateProxyUrl,
- proxyType: createProxyType,
- setProxyType: setCreateProxyType,
creating,
handleCreate,
} = useSessionCreateForm({
@@ -354,6 +347,7 @@ export function Sessions() {
setProxyEnabled(false);
setProxyUrl('');
setProxyUrlError(null);
+ setProxyLoadFailed(false);
if (!proxySessionId) return;
let cancelled = false;
setProxyLoading(true);
@@ -366,7 +360,8 @@ export function Sessions() {
})
.catch(err => {
if (!cancelled) {
- toast.error(t('sessions.proxy.saveError'), err instanceof Error ? err.message : t('common.unknownError'));
+ setProxyLoadFailed(true);
+ toast.error(t('dashboard.loadError'), err instanceof Error ? err.message : t('common.unknownError'));
}
})
.finally(() => {
@@ -375,7 +370,11 @@ export function Sessions() {
return () => {
cancelled = true;
};
- }, [proxySessionId, t, toast]);
+ // Only the session being edited belongs in here. `t` and `toast` are recreated on every render of
+ // their providers (ToastContext hands out a fresh object literal), so listing them re-runs this
+ // effect whenever any toast appears or auto-dismisses, wiping the URL mid-typing.
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [proxySessionId]);
const handleProxySave = async () => {
if (!proxySession) return;
@@ -482,8 +481,9 @@ export function Sessions() {
const existingSessionNames = sessions.map(s => s.name);
// Empty is a disabled button, not a message: the form stays quiet until the user types something.
const nameIssues = newSessionName ? sessionNameIssues(newSessionName, existingSessionNames) : [];
- const createProxyInvalid =
- useProxy && (!createProxyUrl.trim() || (createProxyUrl.trim() && !isValidProxyUrl(createProxyUrl.trim())));
+ // One term: isValidProxyUrl rejects '' too, so the emptiness check was redundant, and its
+ // `string && boolean` shape widened this to `boolean | ""`, which the disabled prop rejects.
+ const createProxyInvalid = useProxy && !isValidProxyUrl(createProxyUrl.trim());
if (loading) {
return (
@@ -612,12 +612,6 @@ export function Sessions() {
value={createProxyUrl}
onChange={e => setCreateProxyUrl(e.target.value)}
/>
- <label htmlFor="create-proxy-type">{t('sessions.proxy.type')}</label>
- <CustomSelect
- value={createProxyType}
- onChange={value => setCreateProxyType(value as SessionProxyType)}
- options={PROXY_TYPE_OPTIONS}
- />
{createProxyInvalid && createProxyUrl.trim() && (
<p className="input-error">{t('sessions.proxy.invalidUrl')}</p>
)}
@@ -850,7 +844,7 @@ export function Sessions() {
<button className="btn-secondary" onClick={() => setProxySession(null)}>
{t('common.cancel')}
</button>
- {canWrite && (
+ {canWrite && !proxyLoadFailed && (
<button
className="btn-primary"
onClick={() => void handleProxySave()}
@@ -866,6 +860,14 @@ export function Sessions() {
<div style={{ display: 'flex', justifyContent: 'center', padding: '2rem' }}>
<Loader2 className="animate-spin" size={24} />
</div>
+ ) : proxyLoadFailed ? (
+ // No form at all: an editable form defaulting to "off" invites a Save that clears a
+ // proxy nobody could read back, credentials included.
+ <div className="detail-grid proxy-form-section">
+ <div className="detail-item">
+ <span className="detail-value">{t('dashboard.loadError')}</span>
+ </div>
+ </div>
) : (
<div className="detail-grid proxy-form-section">
<div className="detail-item">
diff --git a/dashboard/src/services/api.ts b/dashboard/src/services/api.ts
index ae114e46c..7c01a5671 100644
--- a/dashboard/src/services/api.ts
+++ b/dashboard/src/services/api.ts
@@ -774,7 +774,7 @@ export const sessionApi = {
method: 'POST',
body: JSON.stringify({
name,
- ...(options?.proxyUrl ? { proxyUrl: options.proxyUrl, proxyType: options.proxyType ?? 'http' } : {}),
+ ...(options?.proxyUrl ? { proxyUrl: options.proxyUrl } : {}),
}),
}),
delete: (id: string) => request<void>(`/sessions/${id}`, { method: 'DELETE' }),