@tabl.io/auth 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/dist/index.d.ts +24 -0
  2. package/dist/index.js +2364 -1045
  3. package/package.json +4 -2
package/dist/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { JSX } from 'react/jsx-runtime';
2
2
  import { PersistOptions } from 'zustand/middleware';
3
+ import { QueryClient } from '@tanstack/react-query';
4
+ import { QueryClientConfig } from '@tanstack/react-query';
3
5
  import { ReactNode } from 'react';
4
6
  import { StoreApi } from 'zustand';
5
7
  import { SupabaseClient } from '@supabase/supabase-js';
@@ -21,6 +23,28 @@ export declare interface AuthState {
21
23
  signOut: (supabase: SupabaseClient) => Promise<void>;
22
24
  }
23
25
 
26
+ /**
27
+ * Cria um QueryClient com tratamento centralizado de token JWT expirado.
28
+ *
29
+ * Comportamento ao detectar erro de token:
30
+ * 1. Tenta renovar a sessão via `supabase.auth.refreshSession()` (uma única
31
+ * tentativa — requisições simultâneas são deduplicadas).
32
+ * 2. Sucesso → invalida as queries afetadas para refetch transparente.
33
+ * 3. Falha → chama `supabase.auth.signOut()`. O `onAuthStateChange` existente
34
+ * no `useAuthStore.init()` detecta o evento e reseta o estado, fazendo o
35
+ * App re-renderizar para a LoginPage sem nenhum código extra.
36
+ *
37
+ * @example
38
+ * // main.tsx
39
+ * import { supabase } from './api/supabase'
40
+ * import { createAuthAwareQueryClient } from '@tabl.io/auth'
41
+ *
42
+ * const queryClient = createAuthAwareQueryClient(supabase, {
43
+ * defaultOptions: { queries: { staleTime: 0, gcTime: 0 } },
44
+ * })
45
+ */
46
+ export declare function createAuthAwareQueryClient(supabase: SupabaseClient, options?: Omit<QueryClientConfig, 'queryCache'>): QueryClient;
47
+
24
48
  /**
25
49
  * Cria um cliente Supabase com as configurações padrão dos apps Tabl.
26
50
  * Cada app instancia o seu próprio cliente via esta factory.