@riligar/auth-react 1.16.0 → 1.17.0
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.esm.js +16 -10
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +16 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -22,14 +22,17 @@ const getEnvVar = key => {
|
|
|
22
22
|
};
|
|
23
23
|
let API_BASE = (typeof window !== 'undefined' && window?.location ? getEnvVar('VITE_API_BASE') : null) || 'http://localhost:3000';
|
|
24
24
|
let API_KEY = null;
|
|
25
|
+
let INTERNAL_MODE = false; // Modo interno: não exige API Key (para aplicações same-domain)
|
|
25
26
|
|
|
26
|
-
// Permite configurar a API base e
|
|
27
|
+
// Permite configurar a API base, key e modo interno externamente (chamado pelo AuthProvider)
|
|
27
28
|
function configure({
|
|
28
29
|
apiUrl,
|
|
29
|
-
apiKey
|
|
30
|
+
apiKey,
|
|
31
|
+
internal = false
|
|
30
32
|
}) {
|
|
31
33
|
if (apiUrl) API_BASE = apiUrl.replace(/\/$/, ''); // Remove trailing slash
|
|
32
34
|
if (apiKey) API_KEY = apiKey;
|
|
35
|
+
INTERNAL_MODE = internal;
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
// helper fetch pré-configurado
|
|
@@ -51,8 +54,8 @@ async function api(route, opts = {}) {
|
|
|
51
54
|
headers.Authorization = `Bearer ${token}`;
|
|
52
55
|
}
|
|
53
56
|
|
|
54
|
-
// Adiciona API Key se configurada
|
|
55
|
-
if (API_KEY) {
|
|
57
|
+
// Adiciona API Key se configurada e não estiver em modo interno
|
|
58
|
+
if (API_KEY && !INTERNAL_MODE) {
|
|
56
59
|
headers['X-API-Key'] = API_KEY;
|
|
57
60
|
}
|
|
58
61
|
const res = await fetch(url, {
|
|
@@ -884,11 +887,14 @@ function AuthProvider({
|
|
|
884
887
|
apiUrl,
|
|
885
888
|
// URL base da API (OBRIGATÓRIA)
|
|
886
889
|
apiKey,
|
|
887
|
-
// API Key para header X-API-Key (
|
|
890
|
+
// API Key para header X-API-Key (obrigatória exceto em modo internal)
|
|
891
|
+
internal = false,
|
|
892
|
+
// Modo interno: não exige API Key (para aplicações same-domain como dashboard)
|
|
888
893
|
onError // Callback de erro global
|
|
889
894
|
}) {
|
|
890
895
|
// Validação de props obrigatórias
|
|
891
|
-
|
|
896
|
+
// apiKey só é obrigatória se não estiver em modo internal
|
|
897
|
+
if (!internal && !apiKey) {
|
|
892
898
|
throw new Error('[@riligar/auth-react] apiKey é obrigatória no AuthProvider. ' + 'Obtenha sua API Key no dashboard em https://dashboard.myauth.click');
|
|
893
899
|
}
|
|
894
900
|
if (!apiUrl) {
|
|
@@ -898,15 +904,15 @@ function AuthProvider({
|
|
|
898
904
|
const startRefresh = useAuthStore(s => s.startRefresh);
|
|
899
905
|
const checkTokenValidity = useAuthStore(s => s.checkTokenValidity);
|
|
900
906
|
|
|
901
|
-
// Configura SDK com apiUrl e
|
|
902
|
-
// Configura SDK com apiUrl e apiKey
|
|
907
|
+
// Configura SDK com apiUrl, apiKey e modo interno
|
|
903
908
|
// Usamos useMemo para garantir que a configuração ocorra ANTES dos efeitos dos componentes filhos
|
|
904
909
|
useMemo(() => {
|
|
905
910
|
configure({
|
|
906
911
|
apiUrl,
|
|
907
|
-
apiKey
|
|
912
|
+
apiKey,
|
|
913
|
+
internal
|
|
908
914
|
});
|
|
909
|
-
}, [apiUrl, apiKey]);
|
|
915
|
+
}, [apiUrl, apiKey, internal]);
|
|
910
916
|
useEffect(() => {
|
|
911
917
|
init();
|
|
912
918
|
startRefresh();
|