diff --git a/apps/desktop/src/main.tsx b/apps/desktop/src/main.tsx index 973d15b..ac79231 100644 --- a/apps/desktop/src/main.tsx +++ b/apps/desktop/src/main.tsx @@ -1349,6 +1349,10 @@ const resolvedAppUrl = useMemo(() => { const openSystem = useCallback(async () => { if (!token) return + if (!isMachineActive) { + setIsLaunchingSystem(false) + return + } setIsLaunchingSystem(true) // Recarrega store do disco para pegar dados que o Rust salvou diretamente @@ -1408,7 +1412,6 @@ const resolvedAppUrl = useMemo(() => { setError(null) } if (!currentActive) { - setError("Esta dispositivo está desativada. Entre em contato com o suporte da Rever para reativar o acesso.") setIsLaunchingSystem(false) return } @@ -1416,14 +1419,8 @@ const resolvedAppUrl = useMemo(() => { } } else { if (res.status === 423) { - const payload = await res.clone().json().catch(() => null) - const message = - payload && typeof payload === "object" && typeof (payload as { error?: unknown }).error === "string" - ? ((payload as { error?: string }).error ?? "").trim() - : "" setIsMachineActive(false) setIsLaunchingSystem(false) - setError(message.length > 0 ? message : "Esta dispositivo está desativada. Entre em contato com o suporte da Rever.") return } // Se sessão falhar, tenta identificar token inválido/expirado @@ -1473,7 +1470,7 @@ const resolvedAppUrl = useMemo(() => { const url = `${safeAppUrl}/machines/handshake?token=${encodeURIComponent(token)}&redirect=${encodeURIComponent(redirectTarget)}` logDesktop("openSystem:redirect", { url: url.replace(/token=[^&]+/, "token=***") }) window.location.href = url - }, [token, config?.accessRole, config?.machineId, resolvedAppUrl, store]) + }, [token, config?.accessRole, config?.machineId, resolvedAppUrl, store, isMachineActive]) async function reprovision() { if (!store) return @@ -1578,10 +1575,11 @@ const resolvedAppUrl = useMemo(() => { if (!token) return if (autoLaunchRef.current) return if (!tokenVerifiedRef.current) return + if (!isMachineActive) return // Não redireciona se a máquina estiver desativada autoLaunchRef.current = true setIsLaunchingSystem(true) openSystem() - }, [token, status, config?.accessRole, openSystem, tokenValidationTick]) + }, [token, status, config?.accessRole, openSystem, tokenValidationTick, isMachineActive]) // Quando há token persistido (dispositivo já provisionado) e ainda não // disparamos o auto-launch, exibimos diretamente a tela de loading da diff --git a/src/app/api/machines/sessions/route.ts b/src/app/api/machines/sessions/route.ts index a7c19c7..ce30382 100644 --- a/src/app/api/machines/sessions/route.ts +++ b/src/app/api/machines/sessions/route.ts @@ -127,7 +127,7 @@ export async function POST(request: Request) { } catch (error) { if (error instanceof MachineInactiveError) { return jsonWithCors( - { error: "Dispositivo desativada. Entre em contato com o suporte da Rever para reativar o acesso." }, + { error: "Dispositivo desativado. Entre em contato com o suporte da Rever para reativar o acesso." }, 423, origin, CORS_METHODS diff --git a/src/app/machines/handshake/route.ts b/src/app/machines/handshake/route.ts index 3a6521f..4a322c3 100644 --- a/src/app/machines/handshake/route.ts +++ b/src/app/machines/handshake/route.ts @@ -9,7 +9,7 @@ const INACTIVE_TEMPLATE = ` - Dispositivo desativada + Dispositivo desativado