feat: implement user consent verification and redirection for LGPD compliance in dashboard layout and consent term page
This commit is contained in:
@@ -1,10 +1,49 @@
|
||||
<script lang="ts">
|
||||
import { page } from '$app/state';
|
||||
import { useQuery } from 'convex-svelte';
|
||||
import { api } from '@sgse-app/backend/convex/_generated/api';
|
||||
import ActionGuard from '$lib/components/ActionGuard.svelte';
|
||||
import { Toaster } from 'svelte-sonner';
|
||||
import PushNotificationManager from '$lib/components/PushNotificationManager.svelte';
|
||||
const { children } = $props();
|
||||
|
||||
// Usuário atual e consentimento LGPD
|
||||
const currentUser = useQuery(api.auth.getCurrentUser, {});
|
||||
const consentimentoLGPD = useQuery(api.lgpd.verificarConsentimento, { tipo: 'termo_uso' });
|
||||
|
||||
// Redirecionar para o termo de consentimento se obrigatório e não aceito
|
||||
$effect(() => {
|
||||
const p = page.url.pathname;
|
||||
|
||||
// Rotas públicas/que não exigem termo
|
||||
if (
|
||||
p === '/' ||
|
||||
p === '/abrir-chamado' ||
|
||||
p === '/termo-consentimento' ||
|
||||
p.startsWith('/privacidade') ||
|
||||
p.startsWith('/api/')
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Precisa estar autenticado para exigir LGPD
|
||||
if (!currentUser?.data) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Query ainda carregando ou sem dados
|
||||
if (!consentimentoLGPD?.data) {
|
||||
return;
|
||||
}
|
||||
|
||||
const data = consentimentoLGPD.data;
|
||||
|
||||
if (data.termoObrigatorio && !data.aceito) {
|
||||
const redirect = encodeURIComponent(p);
|
||||
window.location.href = `/termo-consentimento?redirect=${redirect}`;
|
||||
}
|
||||
});
|
||||
|
||||
// Resolver recurso/ação a partir da rota
|
||||
const routeAction = $derived.by(() => {
|
||||
const p = page.url.pathname;
|
||||
|
||||
Reference in New Issue
Block a user