feat: update ESLint and TypeScript configurations across frontend and backend; enhance component structure and improve data handling in various modules
This commit is contained in:
@@ -1,26 +1,28 @@
|
||||
/**
|
||||
* Hook para garantir que o cliente Convex tenha o token configurado
|
||||
*
|
||||
*
|
||||
* NOTA: O token é passado automaticamente via monkey patch no +layout.svelte
|
||||
* Este hook existe apenas para compatibilidade, mas não faz nada agora.
|
||||
* O token é injetado via headers nas requisições HTTP através do monkey patch.
|
||||
*/
|
||||
|
||||
import { authStore } from "$lib/stores/auth.svelte";
|
||||
import { authStore } from '$lib/stores/auth.svelte';
|
||||
|
||||
/**
|
||||
* Configura o token no cliente Convex
|
||||
*
|
||||
*
|
||||
* IMPORTANTE: O token agora é passado automaticamente via monkey patch global.
|
||||
* Este hook é mantido para compatibilidade mas não precisa ser chamado.
|
||||
*
|
||||
*
|
||||
* @param client - Cliente Convex retornado por useConvexClient()
|
||||
*/
|
||||
export function setupConvexAuth(client: unknown) {
|
||||
// Token é passado automaticamente via monkey patch em +layout.svelte
|
||||
// Não precisamos fazer nada aqui, apenas manter compatibilidade
|
||||
if (import.meta.env.DEV && client && authStore.token) {
|
||||
console.log("✅ [setupConvexAuth] Token disponível (gerenciado via monkey patch):", authStore.token.substring(0, 20) + "...");
|
||||
}
|
||||
// Token é passado automaticamente via monkey patch em +layout.svelte
|
||||
// Não precisamos fazer nada aqui, apenas manter compatibilidade
|
||||
if (import.meta.env.DEV && client && authStore.token) {
|
||||
console.log(
|
||||
'✅ [setupConvexAuth] Token disponível (gerenciado via monkey patch):',
|
||||
authStore.token.substring(0, 20) + '...'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
/**
|
||||
* Hook personalizado que garante autenticação no Convex
|
||||
*
|
||||
*
|
||||
* Este hook substitui useConvexClient e garante que o token seja sempre passado
|
||||
*
|
||||
*
|
||||
* NOTA: Este hook deve ser usado dentro de componentes Svelte com $effect
|
||||
*/
|
||||
|
||||
import { useConvexClient } from "convex-svelte";
|
||||
import { authStore } from "$lib/stores/auth.svelte";
|
||||
import { useConvexClient } from 'convex-svelte';
|
||||
import { authStore } from '$lib/stores/auth.svelte';
|
||||
|
||||
interface ConvexClientWithAuth {
|
||||
setAuth?: (token: string) => void;
|
||||
clearAuth?: () => void;
|
||||
setAuth?: (token: string) => void;
|
||||
clearAuth?: () => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook que retorna cliente Convex com autenticação configurada automaticamente
|
||||
*
|
||||
*
|
||||
* IMPORTANTE: Use $effect() no componente para chamar esta função:
|
||||
* ```svelte
|
||||
* $effect(() => {
|
||||
@@ -25,31 +25,36 @@ interface ConvexClientWithAuth {
|
||||
* ```
|
||||
*/
|
||||
export function useConvexWithAuth() {
|
||||
const client = useConvexClient();
|
||||
const token = authStore.token;
|
||||
const clientWithAuth = client as ConvexClientWithAuth;
|
||||
|
||||
// Configurar token se disponível
|
||||
if (clientWithAuth && token) {
|
||||
try {
|
||||
// Tentar setAuth se disponível
|
||||
if (typeof clientWithAuth.setAuth === "function") {
|
||||
clientWithAuth.setAuth(token);
|
||||
if (import.meta.env.DEV) {
|
||||
console.log("✅ [useConvexWithAuth] Token configurado via setAuth:", token.substring(0, 20) + "...");
|
||||
}
|
||||
} else {
|
||||
// Se setAuth não estiver disponível, o token deve ser passado via createSvelteAuthClient
|
||||
if (import.meta.env.DEV) {
|
||||
console.log("ℹ️ [useConvexWithAuth] Token disponível, autenticação gerenciada por createSvelteAuthClient");
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn("⚠️ [useConvexWithAuth] Erro ao configurar token:", e);
|
||||
}
|
||||
} else if (!token && import.meta.env.DEV) {
|
||||
console.warn("⚠️ [useConvexWithAuth] Token não disponível");
|
||||
}
|
||||
|
||||
return client;
|
||||
const client = useConvexClient();
|
||||
const token = authStore.token;
|
||||
const clientWithAuth = client as ConvexClientWithAuth;
|
||||
|
||||
// Configurar token se disponível
|
||||
if (clientWithAuth && token) {
|
||||
try {
|
||||
// Tentar setAuth se disponível
|
||||
if (typeof clientWithAuth.setAuth === 'function') {
|
||||
clientWithAuth.setAuth(token);
|
||||
if (import.meta.env.DEV) {
|
||||
console.log(
|
||||
'✅ [useConvexWithAuth] Token configurado via setAuth:',
|
||||
token.substring(0, 20) + '...'
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// Se setAuth não estiver disponível, o token deve ser passado via createSvelteAuthClient
|
||||
if (import.meta.env.DEV) {
|
||||
console.log(
|
||||
'ℹ️ [useConvexWithAuth] Token disponível, autenticação gerenciada por createSvelteAuthClient'
|
||||
);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('⚠️ [useConvexWithAuth] Erro ao configurar token:', e);
|
||||
}
|
||||
} else if (!token && import.meta.env.DEV) {
|
||||
console.warn('⚠️ [useConvexWithAuth] Token não disponível');
|
||||
}
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user