academe-kit 0.5.5 → 0.5.6

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 CHANGED
@@ -5855,15 +5855,50 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
5855
5855
  // Ref para armazenar o resolver da Promise de token
5856
5856
  const tokenReadyResolverRef = React2.useRef(null);
5857
5857
  const tokenReadyPromiseRef = React2.useRef(null);
5858
+ // Estados para controle de token injetado pelo mobile
5859
+ const [mobileToken, setMobileToken] = React2.useState(undefined);
5860
+ const [isMobileWebView, setIsMobileWebView] = React2.useState(false);
5858
5861
  // Extrair valores primitivos do auth para usar como dependências estáveis
5859
5862
  const isAuthenticated = auth.isAuthenticated;
5860
5863
  const isLoading = auth.isLoading;
5861
5864
  const activeNavigator = auth.activeNavigator;
5862
- const accessToken = auth.user?.access_token;
5865
+ const oidcAccessToken = auth.user?.access_token;
5863
5866
  const userProfile = auth.user?.profile;
5864
5867
  const userProfileSub = auth.user?.profile?.sub;
5868
+ // Token a ser usado: prioriza mobile, depois OIDC
5869
+ const accessToken = isMobileWebView ? mobileToken : oidcAccessToken;
5870
+ // --- 0. Detectar Mobile WebView e escutar eventos de token ---
5871
+ React2.useEffect(() => {
5872
+ // Verificar se já tem token injetado (Android - injeta antes do load)
5873
+ if (typeof window !== "undefined" && window.keycloakConfig?.fromMobile) {
5874
+ setIsMobileWebView(true);
5875
+ setMobileToken(window.keycloakConfig.token);
5876
+ }
5877
+ // Escutar evento de injeção (iOS - pode injetar após o load)
5878
+ const handleInjection = (event) => {
5879
+ setIsMobileWebView(true);
5880
+ setMobileToken(event.detail.token);
5881
+ };
5882
+ // Escutar evento de refresh do token
5883
+ const handleTokenRefresh = (event) => {
5884
+ setMobileToken(event.detail.token);
5885
+ };
5886
+ if (typeof window !== "undefined") {
5887
+ window.addEventListener("keycloakConfigInjected", handleInjection);
5888
+ window.addEventListener("keycloakTokenRefreshed", handleTokenRefresh);
5889
+ }
5890
+ return () => {
5891
+ if (typeof window !== "undefined") {
5892
+ window.removeEventListener("keycloakConfigInjected", handleInjection);
5893
+ window.removeEventListener("keycloakTokenRefreshed", handleTokenRefresh);
5894
+ }
5895
+ };
5896
+ }, []);
5865
5897
  // --- 1. Silent Check Inicial (Check SSO) ---
5866
5898
  React2.useEffect(() => {
5899
+ // Não tentar silent login no mobile WebView
5900
+ if (isMobileWebView)
5901
+ return;
5867
5902
  if (!isAuthenticated &&
5868
5903
  !isLoading &&
5869
5904
  !activeNavigator &&
@@ -5874,7 +5909,7 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
5874
5909
  });
5875
5910
  }
5876
5911
  // eslint-disable-next-line react-hooks/exhaustive-deps
5877
- }, [isAuthenticated, isLoading, activeNavigator]);
5912
+ }, [isAuthenticated, isLoading, activeNavigator, isMobileWebView]);
5878
5913
  // --- 2. Configuração de API e Services ---
5879
5914
  // Ref para armazenar o token atual (acessível no middleware)
5880
5915
  const currentTokenRef = React2.useRef(undefined);
@@ -6051,7 +6086,7 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
6051
6086
  user: currentUser,
6052
6087
  refreshUserData,
6053
6088
  signOut,
6054
- isAuthenticated: () => isAuthenticated,
6089
+ isAuthenticated: () => isMobileWebView ? !!mobileToken : isAuthenticated,
6055
6090
  hasSchool,
6056
6091
  goToLogin,
6057
6092
  hasRealmRole,
@@ -6073,6 +6108,8 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
6073
6108
  accessToken,
6074
6109
  apiClient,
6075
6110
  services,
6111
+ isMobileWebView,
6112
+ mobileToken,
6076
6113
  ]);
6077
6114
  return (jsxRuntime.jsx(SecurityContext.Provider, { value: contextValue, children: children }));
6078
6115
  };