From 98f7233cdb095b730f234f5b5cabbd0b17e4a96d Mon Sep 17 00:00:00 2001 From: Marc Brooks Date: Wed, 29 Oct 2025 12:09:02 -0500 Subject: [PATCH] Switch to throwing redirect for welcome or login-local needed Also cleaned up the loader function error-state returns --- ui/src/main.tsx | 4 ++-- ui/src/routes/devices.$id.deregister.tsx | 2 +- ui/src/routes/devices.$id.rename.tsx | 2 +- ui/src/routes/devices.$id.tsx | 2 -- ui/src/routes/devices.tsx | 4 ++-- 5 files changed, 6 insertions(+), 8 deletions(-) diff --git a/ui/src/main.tsx b/ui/src/main.tsx index 8c9c6d18..b3001a69 100644 --- a/ui/src/main.tsx +++ b/ui/src/main.tsx @@ -73,10 +73,10 @@ export async function checkDeviceAuth() { .GET(`${DEVICE_API}/device/status`) .then(res => res.json() as Promise); - if (!res.isSetup) return redirect("/welcome"); + if (!res.isSetup) throw redirect("/welcome"); const deviceRes = await api.GET(`${DEVICE_API}/device`); - if (deviceRes.status === 401) return redirect("/login-local"); + if (deviceRes.status === 401) throw redirect("/login-local"); if (deviceRes.ok) { const device = (await deviceRes.json()) as LocalDevice; return { authMode: device.authMode }; diff --git a/ui/src/routes/devices.$id.deregister.tsx b/ui/src/routes/devices.$id.deregister.tsx index d0b821db..07db5d7d 100644 --- a/ui/src/routes/devices.$id.deregister.tsx +++ b/ui/src/routes/devices.$id.deregister.tsx @@ -58,7 +58,7 @@ const loader: LoaderFunction = async ({ params }: LoaderFunctionArgs) => { return { device, user }; } catch (e) { console.error(e); - return { devices: [] }; + return { user }; } }; diff --git a/ui/src/routes/devices.$id.rename.tsx b/ui/src/routes/devices.$id.rename.tsx index b61dc45a..a7191764 100644 --- a/ui/src/routes/devices.$id.rename.tsx +++ b/ui/src/routes/devices.$id.rename.tsx @@ -54,7 +54,7 @@ const loader: LoaderFunction = async ({ params }: LoaderFunctionArgs) => { return { device, user }; } catch (e) { console.error(e); - return { devices: [] }; + return { user }; } }; diff --git a/ui/src/routes/devices.$id.tsx b/ui/src/routes/devices.$id.tsx index 2e872c84..bae8faa6 100644 --- a/ui/src/routes/devices.$id.tsx +++ b/ui/src/routes/devices.$id.tsx @@ -78,10 +78,8 @@ const deviceLoader = async () => { const cloudLoader = async (params: Params): Promise => { const user = await checkAuth(); - const iceResp = await api.POST(`${CLOUD_API}/webrtc/ice_config`); const iceConfig = await iceResp.json(); - const deviceResp = await api.GET(`${CLOUD_API}/devices/${params.id}`); if (!deviceResp.ok) { diff --git a/ui/src/routes/devices.tsx b/ui/src/routes/devices.tsx index f658c73e..c6972e0e 100644 --- a/ui/src/routes/devices.tsx +++ b/ui/src/routes/devices.tsx @@ -16,7 +16,7 @@ interface LoaderData { devices: { id: string; name: string; online: boolean; lastSeen: string }[]; user: User; } -const loader: LoaderFunction = async ()=> { +const loader: LoaderFunction = async () => { const user = await checkAuth(); try { @@ -30,7 +30,7 @@ const loader: LoaderFunction = async ()=> { return { devices, user }; } catch (e) { console.error(e); - return { devices: [] }; + return { devices: [], user }; } };