refactor: remove countdown timer and redirect logic from MenuProtection component to streamline access denial handling

This commit is contained in:
2025-10-27 11:47:36 -03:00
parent 42cb78e779
commit 3a1956f83b
5 changed files with 798 additions and 43 deletions

View File

@@ -24,7 +24,6 @@
let verificando = $state(true);
let temPermissao = $state(false);
let motivoNegacao = $state("");
let segundosRestantes = $state(3);
// Query para verificar permissões (só executa se o usuário estiver autenticado)
const permissaoQuery = $derived(
@@ -86,22 +85,6 @@
verificando = false;
temPermissao = false;
motivoNegacao = "access_denied";
segundosRestantes = 3;
// Contador regressivo
const intervalo = setInterval(() => {
segundosRestantes--;
if (segundosRestantes <= 0) {
clearInterval(intervalo);
}
}, 1000);
// Aguardar 3 segundos antes de redirecionar
setTimeout(() => {
clearInterval(intervalo);
const currentPath = window.location.pathname;
window.location.href = `${redirectTo}?error=access_denied&route=${encodeURIComponent(currentPath)}`;
}, 3000);
return;
}
@@ -110,22 +93,6 @@
verificando = false;
temPermissao = false;
motivoNegacao = "write_denied";
segundosRestantes = 3;
// Contador regressivo
const intervalo = setInterval(() => {
segundosRestantes--;
if (segundosRestantes <= 0) {
clearInterval(intervalo);
}
}, 1000);
// Aguardar 3 segundos antes de redirecionar
setTimeout(() => {
clearInterval(intervalo);
const currentPath = window.location.pathname;
window.location.href = `${redirectTo}?error=write_denied&route=${encodeURIComponent(currentPath)}`;
}, 3000);
return;
}
@@ -171,16 +138,7 @@
</svg>
</div>
<h2 class="text-2xl font-bold text-base-content mb-2">Acesso Negado</h2>
<p class="text-base-content/70 mb-4">Você não tem permissão para acessar esta página.</p>
<div class="flex items-center justify-center gap-2 mb-4 text-primary">
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
<p class="text-sm font-medium">Redirecionando em <span class="font-bold text-lg">{segundosRestantes}</span> segundo{segundosRestantes !== 1 ? 's' : ''}...</p>
</div>
<button class="btn btn-primary" onclick={() => goto(redirectTo)}>
Voltar Agora
</button>
<p class="text-base-content/70">Você não tem permissão para acessar esta página.</p>
</div>
</div>
{/if}