Mbonea Claude Sonnet 4.6 commited on
Commit
dfe7dfc
Β·
1 Parent(s): 269b3cf

fix(ssid): update portal serverUrl to our server on every SSID set

Browse files

When reusing an existing portal (or re-linking an SSID), the portal's
externalPortal.serverUrl was left pointing to whatever was set before.
Now patches the URL to mbonea-wifibiz.hf.space/portal/{siteId} every
time an SSID is created or updated.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

src/routes/devices.routes.js CHANGED
@@ -631,15 +631,19 @@ router.patch("/:id/ssid", async (req, res) => {
631
  await omada.updatePortalSSID(siteId, portalId, [ssidId]).catch(err =>
632
  console.warn(`[devices/ssid] portal link failed:`, err.message)
633
  );
634
- console.log(`[devices/ssid] device=${device.id} portal linked ssid=${ssidId}`);
 
 
 
635
  } else {
636
  // Portal was never saved β€” check if Omada already has one, otherwise create
637
  try {
638
  const existingPortals = await omada.getPortals(siteId);
639
  if (existingPortals.length > 0) {
640
- // Reuse the first existing portal and link the SSID to it
641
  portalId = existingPortals[0].id;
642
  await omada.updatePortalSSID(siteId, portalId, [ssidId]);
 
643
  console.log(`[devices/ssid] device=${device.id} reusing portal=${portalId}`);
644
  } else {
645
  const deviceName = await db.queryOne(`SELECT name FROM devices WHERE id = ?`, [device.id]).then(r => r?.name || `Device ${device.id}`);
 
631
  await omada.updatePortalSSID(siteId, portalId, [ssidId]).catch(err =>
632
  console.warn(`[devices/ssid] portal link failed:`, err.message)
633
  );
634
+ await omada.updatePortalUrl(siteId, portalId).catch(err =>
635
+ console.warn(`[devices/ssid] portal URL update failed:`, err.message)
636
+ );
637
+ console.log(`[devices/ssid] device=${device.id} portal linked+url updated ssid=${ssidId}`);
638
  } else {
639
  // Portal was never saved β€” check if Omada already has one, otherwise create
640
  try {
641
  const existingPortals = await omada.getPortals(siteId);
642
  if (existingPortals.length > 0) {
643
+ // Reuse the first existing portal β€” link the SSID and fix the server URL
644
  portalId = existingPortals[0].id;
645
  await omada.updatePortalSSID(siteId, portalId, [ssidId]);
646
+ await omada.updatePortalUrl(siteId, portalId);
647
  console.log(`[devices/ssid] device=${device.id} reusing portal=${portalId}`);
648
  } else {
649
  const deviceName = await db.queryOne(`SELECT name FROM devices WHERE id = ?`, [device.id]).then(r => r?.name || `Device ${device.id}`);
src/services/omada.js CHANGED
@@ -289,6 +289,20 @@ async function updatePortalSSID(siteId, portalId, ssidList) {
289
  return omadaRequest('PATCH', `/sites/${siteId}/setting/portals/${portalId}`, { ssidList });
290
  }
291
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
292
  // ── Devices ───────────────────────────────────────────────────────────────────
293
 
294
  async function getSiteDevices(siteId) {
@@ -400,6 +414,7 @@ module.exports = {
400
  getSiteById,
401
  createPortal,
402
  getPortals,
 
403
  getWlans,
404
  getOrCreateWlan,
405
  getSSIDs,
 
289
  return omadaRequest('PATCH', `/sites/${siteId}/setting/portals/${portalId}`, { ssidList });
290
  }
291
 
292
+ async function updatePortalUrl(siteId, portalId) {
293
+ const scheme = process.env.PORTAL_SCHEME || 'https';
294
+ const serverUrl = `${process.env.PORTAL_HOST}/portal/${siteId}`;
295
+ return omadaRequest('PATCH', `/sites/${siteId}/setting/portals/${portalId}`, {
296
+ authType: 4,
297
+ externalPortal: {
298
+ hostType: 2,
299
+ serverUrlScheme: scheme,
300
+ serverUrl,
301
+ logout: false,
302
+ },
303
+ });
304
+ }
305
+
306
  // ── Devices ───────────────────────────────────────────────────────────────────
307
 
308
  async function getSiteDevices(siteId) {
 
414
  getSiteById,
415
  createPortal,
416
  getPortals,
417
+ updatePortalUrl,
418
  getWlans,
419
  getOrCreateWlan,
420
  getSSIDs,