academe-kit 0.3.1 → 0.3.2

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,8 +3279,10 @@ exports.GLOBAL_ROLES = void 0;
3279
3279
  GLOBAL_ROLES["GUARDIAN"] = "guardian";
3280
3280
  })(exports.GLOBAL_ROLES || (exports.GLOBAL_ROLES = {}));
3281
3281
 
3282
- const AcademeAuthProvider = ({ realm, hubUrl, children, clientId, keycloakUrl, apiBaseUrl, }) => {
3283
- return (jsxRuntime.jsx(ReactKeycloakProvider, { authClient: new Keycloak({ clientId, realm, url: keycloakUrl }), children: jsxRuntime.jsx(SecurityProvider, { hubUrl: hubUrl, apiBaseUrl: apiBaseUrl, children: children }) }));
3282
+ 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 }) }));
3284
3286
  };
3285
3287
  const SecurityContext = React.createContext({
3286
3288
  isInitialized: false,
@@ -3294,12 +3296,12 @@ const SecurityContext = React.createContext({
3294
3296
  isAuthenticated: () => false,
3295
3297
  apiClient: null,
3296
3298
  services: null,
3299
+ accessToken: undefined,
3297
3300
  });
3298
- const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", children, }) => {
3301
+ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipApiUserFetch = false, children, }) => {
3299
3302
  const [isInitialized, setIsInitialized] = React.useState(false);
3300
3303
  const [currentUser, setCurrentUser] = React.useState(null);
3301
3304
  const { initialized, keycloak } = useKeycloak();
3302
- // Create API client with the provided baseUrl
3303
3305
  const apiClient = React.useMemo(() => {
3304
3306
  return createAcademeApiClient(apiBaseUrl);
3305
3307
  }, [apiBaseUrl]);
@@ -3330,10 +3332,16 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", child
3330
3332
  lastName: idTokenParsed?.family_name || "",
3331
3333
  };
3332
3334
  }, [keycloak?.idTokenParsed]);
3333
- // Fetch user data from API when authenticated
3334
3335
  React.useEffect(() => {
3335
3336
  const fetchUserData = async () => {
3336
3337
  if (initialized && keycloak?.authenticated && keycloak?.token) {
3338
+ if (skipApiUserFetch) {
3339
+ const academeUser = {
3340
+ keycloakUser: getKeycloakUser(),
3341
+ };
3342
+ setCurrentUser({ ...academeUser, id: keycloak?.idTokenParsed?.sub });
3343
+ return;
3344
+ }
3337
3345
  try {
3338
3346
  const response = await services.user.getMe();
3339
3347
  if (response?.data?.data) {
@@ -3359,9 +3367,17 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", child
3359
3367
  keycloak?.token,
3360
3368
  getKeycloakUser,
3361
3369
  services,
3370
+ skipApiUserFetch,
3362
3371
  ]);
3363
3372
  const refreshUserData = React.useCallback(async () => {
3364
3373
  if (keycloak?.authenticated) {
3374
+ if (skipApiUserFetch) {
3375
+ const academeUser = {
3376
+ keycloakUser: getKeycloakUser(),
3377
+ };
3378
+ setCurrentUser(academeUser);
3379
+ return;
3380
+ }
3365
3381
  try {
3366
3382
  const response = await services.user.getMe();
3367
3383
  if (response?.data?.data) {
@@ -3376,7 +3392,7 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", child
3376
3392
  console.error("Error refreshing user data:", error);
3377
3393
  }
3378
3394
  }
3379
- }, [keycloak?.authenticated, getKeycloakUser, services]);
3395
+ }, [keycloak?.authenticated, getKeycloakUser, services, skipApiUserFetch]);
3380
3396
  const signOut = () => {
3381
3397
  setCurrentUser(null);
3382
3398
  keycloak?.logout();
@@ -3403,6 +3419,7 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", child
3403
3419
  goToLogin: keycloak.login,
3404
3420
  hasRealmRole: keycloak?.hasRealmRole,
3405
3421
  hasClientRole: keycloak.hasResourceRole,
3422
+ accessToken: keycloak?.token,
3406
3423
  apiClient,
3407
3424
  services,
3408
3425
  }, children: children }));
@@ -6575,6 +6592,13 @@ exports.DASHBOARD_ROLES = void 0;
6575
6592
  (function (DASHBOARD_ROLES) {
6576
6593
  })(exports.DASHBOARD_ROLES || (exports.DASHBOARD_ROLES = {}));
6577
6594
 
6595
+ exports.APPLICATIONS_ROLES = void 0;
6596
+ (function (APPLICATIONS_ROLES) {
6597
+ APPLICATIONS_ROLES["ACCESS_NINA"] = "Acesso nina";
6598
+ APPLICATIONS_ROLES["ACCESS_MIKE"] = "Acesso mike";
6599
+ APPLICATIONS_ROLES["VIEW_WIDGET"] = "Visualizar Widget";
6600
+ })(exports.APPLICATIONS_ROLES || (exports.APPLICATIONS_ROLES = {}));
6601
+
6578
6602
  var index = /*#__PURE__*/Object.freeze({
6579
6603
  __proto__: null
6580
6604
  });