academe-kit 0.5.6 → 0.5.7
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 +54 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +54 -13
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -5869,29 +5869,70 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
|
|
|
5869
5869
|
const accessToken = isMobileWebView ? mobileToken : oidcAccessToken;
|
|
5870
5870
|
// --- 0. Detectar Mobile WebView e escutar eventos de token ---
|
|
5871
5871
|
React2.useEffect(() => {
|
|
5872
|
-
|
|
5873
|
-
|
|
5874
|
-
|
|
5875
|
-
|
|
5872
|
+
if (typeof window === "undefined")
|
|
5873
|
+
return;
|
|
5874
|
+
let pollingInterval = null;
|
|
5875
|
+
let pollingAttempts = 0;
|
|
5876
|
+
const MAX_POLLING_ATTEMPTS = 50; // 5 segundos máximo (50 * 100ms)
|
|
5877
|
+
// Função para verificar e configurar o token mobile
|
|
5878
|
+
const checkAndSetMobileToken = () => {
|
|
5879
|
+
if (window.keycloakConfig?.fromMobile && window.keycloakConfig?.token) {
|
|
5880
|
+
console.log('[SecurityProvider] Token mobile detectado via polling');
|
|
5881
|
+
setIsMobileWebView(true);
|
|
5882
|
+
setMobileToken(window.keycloakConfig.token);
|
|
5883
|
+
return true;
|
|
5884
|
+
}
|
|
5885
|
+
return false;
|
|
5886
|
+
};
|
|
5887
|
+
// 1. Verificação imediata
|
|
5888
|
+
if (checkAndSetMobileToken()) {
|
|
5889
|
+
console.log('[SecurityProvider] Token encontrado na verificação inicial');
|
|
5876
5890
|
}
|
|
5877
|
-
|
|
5891
|
+
else {
|
|
5892
|
+
// 2. Polling: verificar a cada 100ms até encontrar o token ou atingir o limite
|
|
5893
|
+
console.log('[SecurityProvider] Iniciando polling para detectar token mobile...');
|
|
5894
|
+
pollingInterval = setInterval(() => {
|
|
5895
|
+
pollingAttempts++;
|
|
5896
|
+
if (checkAndSetMobileToken()) {
|
|
5897
|
+
console.log(`[SecurityProvider] Token encontrado após ${pollingAttempts} tentativas`);
|
|
5898
|
+
if (pollingInterval) {
|
|
5899
|
+
clearInterval(pollingInterval);
|
|
5900
|
+
pollingInterval = null;
|
|
5901
|
+
}
|
|
5902
|
+
}
|
|
5903
|
+
else if (pollingAttempts >= MAX_POLLING_ATTEMPTS) {
|
|
5904
|
+
console.log('[SecurityProvider] Polling encerrado - token não encontrado (não é mobile WebView)');
|
|
5905
|
+
if (pollingInterval) {
|
|
5906
|
+
clearInterval(pollingInterval);
|
|
5907
|
+
pollingInterval = null;
|
|
5908
|
+
}
|
|
5909
|
+
}
|
|
5910
|
+
}, 100);
|
|
5911
|
+
}
|
|
5912
|
+
// 3. Escutar evento de injeção (fallback)
|
|
5878
5913
|
const handleInjection = (event) => {
|
|
5914
|
+
console.log('[SecurityProvider] Token recebido via evento keycloakConfigInjected');
|
|
5879
5915
|
setIsMobileWebView(true);
|
|
5880
5916
|
setMobileToken(event.detail.token);
|
|
5917
|
+
// Parar polling se ainda estiver rodando
|
|
5918
|
+
if (pollingInterval) {
|
|
5919
|
+
clearInterval(pollingInterval);
|
|
5920
|
+
pollingInterval = null;
|
|
5921
|
+
}
|
|
5881
5922
|
};
|
|
5882
|
-
// Escutar evento de refresh do token
|
|
5923
|
+
// 4. Escutar evento de refresh do token
|
|
5883
5924
|
const handleTokenRefresh = (event) => {
|
|
5925
|
+
console.log('[SecurityProvider] Token atualizado via evento keycloakTokenRefreshed');
|
|
5884
5926
|
setMobileToken(event.detail.token);
|
|
5885
5927
|
};
|
|
5886
|
-
|
|
5887
|
-
|
|
5888
|
-
window.addEventListener("keycloakTokenRefreshed", handleTokenRefresh);
|
|
5889
|
-
}
|
|
5928
|
+
window.addEventListener("keycloakConfigInjected", handleInjection);
|
|
5929
|
+
window.addEventListener("keycloakTokenRefreshed", handleTokenRefresh);
|
|
5890
5930
|
return () => {
|
|
5891
|
-
if (
|
|
5892
|
-
|
|
5893
|
-
window.removeEventListener("keycloakTokenRefreshed", handleTokenRefresh);
|
|
5931
|
+
if (pollingInterval) {
|
|
5932
|
+
clearInterval(pollingInterval);
|
|
5894
5933
|
}
|
|
5934
|
+
window.removeEventListener("keycloakConfigInjected", handleInjection);
|
|
5935
|
+
window.removeEventListener("keycloakTokenRefreshed", handleTokenRefresh);
|
|
5895
5936
|
};
|
|
5896
5937
|
}, []);
|
|
5897
5938
|
// --- 1. Silent Check Inicial (Check SSO) ---
|