refactor: integrate current user data across components

- Replaced instances of `authStore` with `currentUser` to streamline user authentication handling.
- Updated permission checks and user-related data retrieval to utilize the new `useQuery` for better performance and clarity.
- Cleaned up component structures and improved formatting for consistency and readability.
- Enhanced error handling and user feedback mechanisms in various components to improve user experience.
This commit is contained in:
2025-11-08 10:52:33 -03:00
parent 01138b3e1c
commit 9a5f2b294d
28 changed files with 2312 additions and 1235 deletions

View File

@@ -2,9 +2,8 @@
import { useQuery } from "convex-svelte";
import { api } from "@sgse-app/backend/convex/_generated/api";
import type { Id } from "@sgse-app/backend/convex/_generated/dataModel";
import { authStore } from "$lib/stores/auth.svelte";
import { loginModalStore } from "$lib/stores/loginModal.svelte";
import { AlertTriangle } from "lucide-svelte";
import { TriangleAlert } from "lucide-svelte";
interface Props {
recurso: string;
@@ -17,18 +16,21 @@
let verificando = $state(true);
let permitido = $state(false);
// Usuário atual
const currentUser = useQuery(api.auth.getCurrentUser, {});
const permissaoQuery = $derived(
authStore.usuario
currentUser?.data
? useQuery(api.permissoesAcoes.verificarAcao, {
usuarioId: authStore.usuario._id as Id<"usuarios">,
usuarioId: currentUser.data._id as Id<"usuarios">,
recurso,
acao,
})
: null
: null,
);
$effect(() => {
if (!authStore.autenticado) {
if (!currentUser?.data) {
verificando = false;
permitido = false;
const currentPath = window.location.pathname;
@@ -60,7 +62,7 @@
<div class="flex items-center justify-center min-h-screen">
<div class="text-center">
<div class="p-4 bg-error/10 rounded-full inline-block mb-4">
<AlertTriangle class="h-16 w-16 text-error" strokeWidth={2} />
<TriangleAlert class="h-16 w-16 text-error" strokeWidth={2} />
</div>
<h2 class="text-2xl font-bold text-base-content mb-2">Acesso Negado</h2>
<p class="text-base-content/70">