-
-
-
+
+ Acesso bloqueado
+
Máquina desativada
-
- Esta máquina foi desativada temporariamente por um administrador da Rever. Enquanto estiver nessa situação,
- o acesso ao portal e o envio de informações ficam bloqueados.
+
+ Esta máquina foi desativada temporariamente pelos administradores. Enquanto isso, o acesso ao portal e o
+ envio de informações ficam indisponíveis.
{companyName ? (
-
+
{companyName}
) : null}
-
diff --git a/src/lib/auth-client.tsx b/src/lib/auth-client.tsx
index 4e0c820..5cc579e 100644
--- a/src/lib/auth-client.tsx
+++ b/src/lib/auth-client.tsx
@@ -217,6 +217,57 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
}
}, [session?.user])
+ // Poll machine session periodically to reflect admin changes (e.g., deactivation)
+ useEffect(() => {
+ const shouldPoll = Boolean(session?.user?.role === "machine") || Boolean(machineContext)
+ if (!shouldPoll) return
+ let cancelled = false
+ const tick = async () => {
+ try {
+ const response = await fetch("/api/machines/session", { credentials: "include" })
+ if (!response.ok) return
+ const data = await response.json()
+ if (cancelled) return
+ const mc = data?.machine
+ if (mc && typeof mc === "object") {
+ setMachineContext((prev) => {
+ // only update when something changes to avoid re-renders
+ const next = {
+ machineId: mc.id,
+ tenantId: mc.tenantId,
+ persona: mc.persona ?? null,
+ assignedUserId: mc.assignedUserId ?? null,
+ assignedUserEmail: mc.assignedUserEmail ?? null,
+ assignedUserName: mc.assignedUserName ?? null,
+ assignedUserRole: mc.assignedUserRole ?? null,
+ companyId: mc.companyId ?? null,
+ isActive: (mc.isActive ?? true) as boolean,
+ } as MachineContext
+ return JSON.stringify(prev) === JSON.stringify(next) ? prev : next
+ })
+ }
+ } catch {
+ /* ignore transient errors */
+ }
+ }
+ const id = setInterval(tick, 15000)
+ // Also refresh when tab gains focus
+ const onFocus = () => tick()
+ if (typeof window !== "undefined") {
+ window.addEventListener("focus", onFocus)
+ document.addEventListener("visibilitychange", onFocus)
+ }
+ tick()
+ return () => {
+ cancelled = true
+ clearInterval(id)
+ if (typeof window !== "undefined") {
+ window.removeEventListener("focus", onFocus)
+ document.removeEventListener("visibilitychange", onFocus)
+ }
+ }
+ }, [session?.user?.role, machineContext])
+
useEffect(() => {
if (!session?.user || session.user.role === "machine" || convexUserId) return