academe-kit 0.5.7 → 0.5.8
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.cjs +37 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +37 -8
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -5858,6 +5858,7 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
|
|
|
5858
5858
|
// Estados para controle de token injetado pelo mobile
|
|
5859
5859
|
const [mobileToken, setMobileToken] = React2.useState(undefined);
|
|
5860
5860
|
const [isMobileWebView, setIsMobileWebView] = React2.useState(false);
|
|
5861
|
+
const [isMobileDetectionComplete, setIsMobileDetectionComplete] = React2.useState(false);
|
|
5861
5862
|
// Extrair valores primitivos do auth para usar como dependências estáveis
|
|
5862
5863
|
const isAuthenticated = auth.isAuthenticated;
|
|
5863
5864
|
const isLoading = auth.isLoading;
|
|
@@ -5873,13 +5874,36 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
|
|
|
5873
5874
|
return;
|
|
5874
5875
|
let pollingInterval = null;
|
|
5875
5876
|
let pollingAttempts = 0;
|
|
5876
|
-
|
|
5877
|
+
// Detectar se estamos em um contexto de Mobile WebView
|
|
5878
|
+
// Verificamos múltiplos indicadores porque no iOS o ReactNativeWebView pode ser injetado depois
|
|
5879
|
+
const urlParams = new URLSearchParams(window.location.search);
|
|
5880
|
+
const isEmbedded = urlParams.get('embedded') === 'true';
|
|
5881
|
+
const hasReactNativeWebView = !!window.ReactNativeWebView;
|
|
5882
|
+
const hasKeycloakConfig = !!window.keycloakConfig?.fromMobile;
|
|
5883
|
+
const shouldCheckForMobileToken = isEmbedded || hasReactNativeWebView || hasKeycloakConfig;
|
|
5884
|
+
console.log('[SecurityProvider] Verificação mobile:', {
|
|
5885
|
+
isEmbedded,
|
|
5886
|
+
hasReactNativeWebView,
|
|
5887
|
+
hasKeycloakConfig,
|
|
5888
|
+
shouldCheckForMobileToken
|
|
5889
|
+
});
|
|
5890
|
+
// Se não há indicadores de mobile, completa imediatamente
|
|
5891
|
+
if (!shouldCheckForMobileToken) {
|
|
5892
|
+
console.log('[SecurityProvider] Não é contexto mobile - pulando detecção');
|
|
5893
|
+
setIsMobileDetectionComplete(true);
|
|
5894
|
+
return;
|
|
5895
|
+
}
|
|
5896
|
+
console.log('[SecurityProvider] Contexto mobile detectado - iniciando detecção de token...');
|
|
5897
|
+
// Polling para mobile: 30 tentativas de 100ms = 3 segundos max
|
|
5898
|
+
const MAX_POLLING_ATTEMPTS = 30;
|
|
5899
|
+
const POLLING_INTERVAL_MS = 100;
|
|
5877
5900
|
// Função para verificar e configurar o token mobile
|
|
5878
5901
|
const checkAndSetMobileToken = () => {
|
|
5879
5902
|
if (window.keycloakConfig?.fromMobile && window.keycloakConfig?.token) {
|
|
5880
|
-
console.log('[SecurityProvider] Token mobile detectado
|
|
5903
|
+
console.log('[SecurityProvider] Token mobile detectado');
|
|
5881
5904
|
setIsMobileWebView(true);
|
|
5882
5905
|
setMobileToken(window.keycloakConfig.token);
|
|
5906
|
+
setIsMobileDetectionComplete(true);
|
|
5883
5907
|
return true;
|
|
5884
5908
|
}
|
|
5885
5909
|
return false;
|
|
@@ -5889,31 +5913,32 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
|
|
|
5889
5913
|
console.log('[SecurityProvider] Token encontrado na verificação inicial');
|
|
5890
5914
|
}
|
|
5891
5915
|
else {
|
|
5892
|
-
// 2. Polling
|
|
5893
|
-
console.log('[SecurityProvider] Iniciando polling para detectar token mobile...');
|
|
5916
|
+
// 2. Polling até encontrar o token ou atingir o limite
|
|
5894
5917
|
pollingInterval = setInterval(() => {
|
|
5895
5918
|
pollingAttempts++;
|
|
5896
5919
|
if (checkAndSetMobileToken()) {
|
|
5897
|
-
console.log(`[SecurityProvider] Token encontrado após ${pollingAttempts} tentativas`);
|
|
5920
|
+
console.log(`[SecurityProvider] Token encontrado após ${pollingAttempts} tentativas (${pollingAttempts * POLLING_INTERVAL_MS}ms)`);
|
|
5898
5921
|
if (pollingInterval) {
|
|
5899
5922
|
clearInterval(pollingInterval);
|
|
5900
5923
|
pollingInterval = null;
|
|
5901
5924
|
}
|
|
5902
5925
|
}
|
|
5903
5926
|
else if (pollingAttempts >= MAX_POLLING_ATTEMPTS) {
|
|
5904
|
-
console.log('[SecurityProvider] Polling encerrado - token não encontrado
|
|
5927
|
+
console.log('[SecurityProvider] Polling encerrado - token não encontrado após 3 segundos');
|
|
5928
|
+
setIsMobileDetectionComplete(true);
|
|
5905
5929
|
if (pollingInterval) {
|
|
5906
5930
|
clearInterval(pollingInterval);
|
|
5907
5931
|
pollingInterval = null;
|
|
5908
5932
|
}
|
|
5909
5933
|
}
|
|
5910
|
-
},
|
|
5934
|
+
}, POLLING_INTERVAL_MS);
|
|
5911
5935
|
}
|
|
5912
5936
|
// 3. Escutar evento de injeção (fallback)
|
|
5913
5937
|
const handleInjection = (event) => {
|
|
5914
5938
|
console.log('[SecurityProvider] Token recebido via evento keycloakConfigInjected');
|
|
5915
5939
|
setIsMobileWebView(true);
|
|
5916
5940
|
setMobileToken(event.detail.token);
|
|
5941
|
+
setIsMobileDetectionComplete(true);
|
|
5917
5942
|
// Parar polling se ainda estiver rodando
|
|
5918
5943
|
if (pollingInterval) {
|
|
5919
5944
|
clearInterval(pollingInterval);
|
|
@@ -6121,8 +6146,11 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
|
|
|
6121
6146
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
6122
6147
|
}, []);
|
|
6123
6148
|
// Memoizar o value do context para evitar re-renders desnecessários
|
|
6149
|
+
// isInitialized só é true quando:
|
|
6150
|
+
// 1. OIDC terminou de carregar (!isLoading)
|
|
6151
|
+
// 2. E a detecção mobile completou (isMobileDetectionComplete)
|
|
6124
6152
|
const contextValue = React2.useMemo(() => ({
|
|
6125
|
-
isInitialized: !isLoading,
|
|
6153
|
+
isInitialized: !isLoading && isMobileDetectionComplete,
|
|
6126
6154
|
isTokenReady,
|
|
6127
6155
|
user: currentUser,
|
|
6128
6156
|
refreshUserData,
|
|
@@ -6137,6 +6165,7 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
|
|
|
6137
6165
|
services,
|
|
6138
6166
|
}), [
|
|
6139
6167
|
isLoading,
|
|
6168
|
+
isMobileDetectionComplete,
|
|
6140
6169
|
isTokenReady,
|
|
6141
6170
|
currentUser,
|
|
6142
6171
|
refreshUserData,
|