academe-kit 0.3.1 → 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.d.ts +14 -4
- package/dist/index.esm.js +46 -8
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +44 -6
- package/dist/index.js.map +1 -1
- package/dist/types/context/SecurityProvider/types.d.ts +7 -3
- package/dist/types/index.d.ts +1 -0
- package/dist/types/roles/applications.d.ts +5 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3279,8 +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
|
-
|
|
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;
|
|
3287
|
+
const AcademeAuthProvider = ({ realm, hubUrl, children, clientId, keycloakUrl, apiBaseUrl, initOptions, skipApiUserFetch, }) => {
|
|
3288
|
+
// 2. Inicialização: Só 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 }) }));
|
|
3284
3299
|
};
|
|
3285
3300
|
const SecurityContext = React.createContext({
|
|
3286
3301
|
isInitialized: false,
|
|
@@ -3294,12 +3309,12 @@ const SecurityContext = React.createContext({
|
|
|
3294
3309
|
isAuthenticated: () => false,
|
|
3295
3310
|
apiClient: null,
|
|
3296
3311
|
services: null,
|
|
3312
|
+
accessToken: undefined,
|
|
3297
3313
|
});
|
|
3298
|
-
const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", children, }) => {
|
|
3314
|
+
const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipApiUserFetch = false, children, }) => {
|
|
3299
3315
|
const [isInitialized, setIsInitialized] = React.useState(false);
|
|
3300
3316
|
const [currentUser, setCurrentUser] = React.useState(null);
|
|
3301
3317
|
const { initialized, keycloak } = useKeycloak();
|
|
3302
|
-
// Create API client with the provided baseUrl
|
|
3303
3318
|
const apiClient = React.useMemo(() => {
|
|
3304
3319
|
return createAcademeApiClient(apiBaseUrl);
|
|
3305
3320
|
}, [apiBaseUrl]);
|
|
@@ -3320,6 +3335,7 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", child
|
|
|
3320
3335
|
setIsInitialized(initialized);
|
|
3321
3336
|
}, [initialized]);
|
|
3322
3337
|
React.useEffect(() => {
|
|
3338
|
+
// @ts-ignore
|
|
3323
3339
|
window.accessToken = keycloak.token;
|
|
3324
3340
|
}, [keycloak.token]);
|
|
3325
3341
|
const getKeycloakUser = React.useCallback(() => {
|
|
@@ -3330,10 +3346,16 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", child
|
|
|
3330
3346
|
lastName: idTokenParsed?.family_name || "",
|
|
3331
3347
|
};
|
|
3332
3348
|
}, [keycloak?.idTokenParsed]);
|
|
3333
|
-
// Fetch user data from API when authenticated
|
|
3334
3349
|
React.useEffect(() => {
|
|
3335
3350
|
const fetchUserData = async () => {
|
|
3336
3351
|
if (initialized && keycloak?.authenticated && keycloak?.token) {
|
|
3352
|
+
if (skipApiUserFetch) {
|
|
3353
|
+
const academeUser = {
|
|
3354
|
+
keycloakUser: getKeycloakUser(),
|
|
3355
|
+
};
|
|
3356
|
+
setCurrentUser({ ...academeUser, id: keycloak?.idTokenParsed?.sub });
|
|
3357
|
+
return;
|
|
3358
|
+
}
|
|
3337
3359
|
try {
|
|
3338
3360
|
const response = await services.user.getMe();
|
|
3339
3361
|
if (response?.data?.data) {
|
|
@@ -3359,9 +3381,17 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", child
|
|
|
3359
3381
|
keycloak?.token,
|
|
3360
3382
|
getKeycloakUser,
|
|
3361
3383
|
services,
|
|
3384
|
+
skipApiUserFetch,
|
|
3362
3385
|
]);
|
|
3363
3386
|
const refreshUserData = React.useCallback(async () => {
|
|
3364
3387
|
if (keycloak?.authenticated) {
|
|
3388
|
+
if (skipApiUserFetch) {
|
|
3389
|
+
const academeUser = {
|
|
3390
|
+
keycloakUser: getKeycloakUser(),
|
|
3391
|
+
};
|
|
3392
|
+
setCurrentUser(academeUser);
|
|
3393
|
+
return;
|
|
3394
|
+
}
|
|
3365
3395
|
try {
|
|
3366
3396
|
const response = await services.user.getMe();
|
|
3367
3397
|
if (response?.data?.data) {
|
|
@@ -3376,7 +3406,7 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", child
|
|
|
3376
3406
|
console.error("Error refreshing user data:", error);
|
|
3377
3407
|
}
|
|
3378
3408
|
}
|
|
3379
|
-
}, [keycloak?.authenticated, getKeycloakUser, services]);
|
|
3409
|
+
}, [keycloak?.authenticated, getKeycloakUser, services, skipApiUserFetch]);
|
|
3380
3410
|
const signOut = () => {
|
|
3381
3411
|
setCurrentUser(null);
|
|
3382
3412
|
keycloak?.logout();
|
|
@@ -3403,6 +3433,7 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", child
|
|
|
3403
3433
|
goToLogin: keycloak.login,
|
|
3404
3434
|
hasRealmRole: keycloak?.hasRealmRole,
|
|
3405
3435
|
hasClientRole: keycloak.hasResourceRole,
|
|
3436
|
+
accessToken: keycloak?.token,
|
|
3406
3437
|
apiClient,
|
|
3407
3438
|
services,
|
|
3408
3439
|
}, children: children }));
|
|
@@ -6575,6 +6606,13 @@ exports.DASHBOARD_ROLES = void 0;
|
|
|
6575
6606
|
(function (DASHBOARD_ROLES) {
|
|
6576
6607
|
})(exports.DASHBOARD_ROLES || (exports.DASHBOARD_ROLES = {}));
|
|
6577
6608
|
|
|
6609
|
+
exports.APPLICATIONS_ROLES = void 0;
|
|
6610
|
+
(function (APPLICATIONS_ROLES) {
|
|
6611
|
+
APPLICATIONS_ROLES["ACCESS_NINA"] = "Acesso nina";
|
|
6612
|
+
APPLICATIONS_ROLES["ACCESS_MIKE"] = "Acesso mike";
|
|
6613
|
+
APPLICATIONS_ROLES["VIEW_WIDGET"] = "Visualizar Widget";
|
|
6614
|
+
})(exports.APPLICATIONS_ROLES || (exports.APPLICATIONS_ROLES = {}));
|
|
6615
|
+
|
|
6578
6616
|
var index = /*#__PURE__*/Object.freeze({
|
|
6579
6617
|
__proto__: null
|
|
6580
6618
|
});
|