academe-kit 0.3.2 → 0.3.3

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
@@ -3279,10 +3279,23 @@ exports.GLOBAL_ROLES = void 0;
3279
3279
  GLOBAL_ROLES["GUARDIAN"] = "guardian";
3280
3280
  })(exports.GLOBAL_ROLES || (exports.GLOBAL_ROLES = {}));
3281
3281
 
3282
+ // --------------------------------------------------------
3283
+ // 1. SINGLETON: Variável declarada FORA do componente
3284
+ // Isso garante que ela sobreviva a re-renders do React
3285
+ // --------------------------------------------------------
3286
+ let globalKeycloak;
3282
3287
  const AcademeAuthProvider = ({ realm, hubUrl, children, clientId, keycloakUrl, apiBaseUrl, initOptions, skipApiUserFetch, }) => {
3283
- const keycloakInstance = React.useMemo(() => new Keycloak({ clientId, realm, url: keycloakUrl }), [clientId, realm, keycloakUrl]);
3284
- const keycloakInitOptions = React.useMemo(() => initOptions, [initOptions]);
3285
- return (jsxRuntime.jsx(ReactKeycloakProvider, { authClient: keycloakInstance, initOptions: keycloakInitOptions, children: jsxRuntime.jsx(SecurityProvider, { hubUrl: hubUrl, apiBaseUrl: apiBaseUrl, skipApiUserFetch: skipApiUserFetch, children: children }) }));
3288
+ // 2. Inicialização: cria se ainda não existir (Singleton)
3289
+ if (!globalKeycloak) {
3290
+ console.log("🦁 [AcademeAuthProvider] Criando Instância Única do Keycloak");
3291
+ globalKeycloak = new Keycloak({ clientId, realm, url: keycloakUrl });
3292
+ }
3293
+ // Mantemos o initOptions memorizado, mas forçamos o logging para debug
3294
+ const keycloakInitOptions = React.useMemo(() => ({
3295
+ ...initOptions,
3296
+ enableLogging: true, // <-- Importante para vermos o fluxo no console
3297
+ }), [initOptions]);
3298
+ return (jsxRuntime.jsx(ReactKeycloakProvider, { authClient: globalKeycloak, initOptions: keycloakInitOptions, children: jsxRuntime.jsx(SecurityProvider, { hubUrl: hubUrl, apiBaseUrl: apiBaseUrl, skipApiUserFetch: skipApiUserFetch, children: children }) }));
3286
3299
  };
3287
3300
  const SecurityContext = React.createContext({
3288
3301
  isInitialized: false,
@@ -3322,6 +3335,7 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
3322
3335
  setIsInitialized(initialized);
3323
3336
  }, [initialized]);
3324
3337
  React.useEffect(() => {
3338
+ // @ts-ignore
3325
3339
  window.accessToken = keycloak.token;
3326
3340
  }, [keycloak.token]);
3327
3341
  const getKeycloakUser = React.useCallback(() => {