@riligar/auth-react 1.20.3 → 1.20.5

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.
package/dist/index.js CHANGED
@@ -10,30 +10,16 @@ var form = require('@mantine/form');
10
10
  var iconsReact = require('@tabler/icons-react');
11
11
  var notifications = require('@mantine/notifications');
12
12
 
13
- var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
14
- // Config - pode ser sobrescrita pelo AuthProvider
15
- // Tenta detectar ambiente Vite, mas falha graciosamente se não existir
16
- const getEnvVar = key => {
17
- try {
18
- if (typeof ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href)) }) !== 'undefined' && undefined && undefined[key]) {
19
- return undefined[key];
20
- }
21
- } catch (e) {
22
- // ignore
23
- }
24
- return null;
25
- };
26
- let API_BASE = (typeof window !== 'undefined' && window?.location ? getEnvVar('VITE_API_BASE') : null) || 'http://localhost:3000';
13
+ // Config - API Base URL fixa para o serviço de autenticação
14
+ const API_BASE = 'https://manager.myauth.click';
27
15
  let API_KEY = null;
28
16
  let INTERNAL_MODE = false; // Modo interno: não exige API Key (para aplicações same-domain)
29
17
 
30
- // Permite configurar a API base, key e modo interno externamente (chamado pelo AuthProvider)
18
+ // Permite configurar API key e modo interno externamente (chamado pelo AuthProvider)
31
19
  function configure({
32
- apiUrl,
33
20
  apiKey,
34
21
  internal = false
35
22
  }) {
36
- if (apiUrl) API_BASE = apiUrl.replace(/\/$/, ''); // Remove trailing slash
37
23
  if (apiKey) API_KEY = apiKey;
38
24
  INTERNAL_MODE = internal;
39
25
  }
@@ -884,8 +870,6 @@ const AuthContext = /*#__PURE__*/react.createContext(); // só para ter o Provid
884
870
 
885
871
  function AuthProvider({
886
872
  children,
887
- apiUrl,
888
- // URL base da API (OBRIGATÓRIA)
889
873
  apiKey,
890
874
  // API Key para header X-API-Key (obrigatória exceto em modo internal)
891
875
  internal = false,
@@ -897,22 +881,18 @@ function AuthProvider({
897
881
  if (!internal && !apiKey) {
898
882
  throw new Error('[@riligar/auth-react] apiKey é obrigatória no AuthProvider. ' + 'Obtenha sua API Key no dashboard em https://dashboard.myauth.click');
899
883
  }
900
- if (!apiUrl) {
901
- throw new Error('[@riligar/auth-react] apiUrl é obrigatória no AuthProvider. ' + 'Use a URL do seu servidor de autenticação.');
902
- }
903
884
  const init = useAuthStore(s => s.init);
904
885
  const startRefresh = useAuthStore(s => s.startRefresh);
905
886
  const checkTokenValidity = useAuthStore(s => s.checkTokenValidity);
906
887
 
907
- // Configura SDK com apiUrl, apiKey e modo interno
888
+ // Configura SDK com apiKey e modo interno
908
889
  // Usamos useMemo para garantir que a configuração ocorra ANTES dos efeitos dos componentes filhos
909
890
  react.useMemo(() => {
910
891
  configure({
911
- apiUrl,
912
892
  apiKey,
913
893
  internal
914
894
  });
915
- }, [apiUrl, apiKey, internal]);
895
+ }, [apiKey, internal]);
916
896
  react.useEffect(() => {
917
897
  init();
918
898
  startRefresh();
@@ -923,9 +903,14 @@ function AuthProvider({
923
903
  if (typeof window === 'undefined') return;
924
904
  const handleStorageChange = event => {
925
905
  if (event.key === 'auth:logout') {
926
- window.location.reload();
906
+ // Limpa o user do store - a aplicação redireciona automaticamente quando user é null
907
+ useAuthStore.setState({
908
+ user: null,
909
+ currentSession: null,
910
+ sessions: []
911
+ });
927
912
  }
928
- // Se o token mudou em outra aba, recarrega
913
+ // Se o token mudou em outra aba, verifica validade
929
914
  if (event.key === 'auth:token') {
930
915
  checkTokenValidity();
931
916
  }