academe-kit 0.8.6 → 0.8.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 +47 -50
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +47 -50
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -6048,7 +6048,6 @@ const AcademeAuthProvider = ({ realm, hubUrl, children, clientId, keycloakUrl, a
|
|
|
6048
6048
|
},
|
|
6049
6049
|
automaticSilentRenew: true,
|
|
6050
6050
|
};
|
|
6051
|
-
console.log("oidc ->", oidcConfig);
|
|
6052
6051
|
return (jsxRuntime.jsx(AuthProvider, { ...oidcConfig, children: jsxRuntime.jsx(SecurityProvider, { hubUrl: hubUrl, apiBaseUrl: apiBaseUrl, skipApiUserFetch: skipApiUserFetch, children: children }) }));
|
|
6053
6052
|
};
|
|
6054
6053
|
const SecurityContext = React2.createContext({
|
|
@@ -6097,7 +6096,7 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
|
|
|
6097
6096
|
const isAuthenticated = auth.isAuthenticated || !!accessToken;
|
|
6098
6097
|
const isLoading = auth.isLoading;
|
|
6099
6098
|
const activeNavigator = auth.activeNavigator;
|
|
6100
|
-
|
|
6099
|
+
auth.user?.profile;
|
|
6101
6100
|
const currentTokenRef = React2.useRef(undefined);
|
|
6102
6101
|
// Efeito para sincronizar o token do auth com o state
|
|
6103
6102
|
// e também verificar cookies periodicamente
|
|
@@ -6205,15 +6204,14 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
|
|
|
6205
6204
|
}
|
|
6206
6205
|
}, [accessToken, isLoading, isAuthenticated]);
|
|
6207
6206
|
const getKeycloakUser = React2.useCallback(() => {
|
|
6208
|
-
const profile = userProfile;
|
|
6209
6207
|
return {
|
|
6210
|
-
email:
|
|
6211
|
-
name:
|
|
6212
|
-
lastName:
|
|
6208
|
+
email: decodedAccessToken?.email || "",
|
|
6209
|
+
name: decodedAccessToken?.given_name || "",
|
|
6210
|
+
lastName: decodedAccessToken?.family_name || "",
|
|
6213
6211
|
avatar_url: decodedAccessToken?.avatar_url,
|
|
6214
6212
|
tm_token: decodedAccessToken?.tm_token,
|
|
6215
6213
|
};
|
|
6216
|
-
}, [
|
|
6214
|
+
}, [decodedAccessToken]);
|
|
6217
6215
|
const hasRealmRole = React2.useCallback((role) => {
|
|
6218
6216
|
return decodedAccessToken?.realm_access?.roles?.includes(role) ?? false;
|
|
6219
6217
|
}, [decodedAccessToken]);
|
|
@@ -6229,51 +6227,50 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
|
|
|
6229
6227
|
return Object.values(decodedAccessToken.resource_access).some((resource) => resource.roles?.includes(role));
|
|
6230
6228
|
}, [decodedAccessToken]);
|
|
6231
6229
|
// --- 4. Fetch de Dados do Usuário (Backend) ---
|
|
6232
|
-
|
|
6233
|
-
|
|
6234
|
-
|
|
6235
|
-
|
|
6236
|
-
|
|
6237
|
-
|
|
6238
|
-
|
|
6239
|
-
|
|
6240
|
-
|
|
6241
|
-
|
|
6242
|
-
|
|
6243
|
-
|
|
6244
|
-
|
|
6245
|
-
|
|
6246
|
-
|
|
6247
|
-
|
|
6248
|
-
const academeUser = {
|
|
6249
|
-
...response.data.data,
|
|
6250
|
-
keycloakUser: getKeycloakUser(),
|
|
6251
|
-
};
|
|
6252
|
-
setCurrentUser(academeUser);
|
|
6253
|
-
}
|
|
6254
|
-
}
|
|
6255
|
-
catch (error) {
|
|
6256
|
-
console.error("[SecurityProvider] Error fetching user data:", error);
|
|
6257
|
-
}
|
|
6230
|
+
// Refs para controlar fetch sem depender de useEffect (componente pode desmontar antes dos efeitos executarem)
|
|
6231
|
+
const hasFetchedUserRef = React2.useRef(false);
|
|
6232
|
+
const isFetchingUserRef = React2.useRef(false);
|
|
6233
|
+
if (!isAuthenticated) {
|
|
6234
|
+
hasFetchedUserRef.current = false;
|
|
6235
|
+
}
|
|
6236
|
+
if (isAuthenticated &&
|
|
6237
|
+
!hasFetchedUserRef.current &&
|
|
6238
|
+
!isFetchingUserRef.current) {
|
|
6239
|
+
if (skipApiUserFetch) {
|
|
6240
|
+
if (decodedAccessToken) {
|
|
6241
|
+
hasFetchedUserRef.current = true;
|
|
6242
|
+
const academeUser = {
|
|
6243
|
+
keycloakUser: getKeycloakUser(),
|
|
6244
|
+
};
|
|
6245
|
+
setCurrentUser({ ...academeUser, id: userProfileSub || "" });
|
|
6258
6246
|
}
|
|
6259
|
-
|
|
6260
|
-
|
|
6261
|
-
|
|
6247
|
+
}
|
|
6248
|
+
else {
|
|
6249
|
+
hasFetchedUserRef.current = true;
|
|
6250
|
+
isFetchingUserRef.current = true;
|
|
6251
|
+
services.user
|
|
6252
|
+
.getMe()
|
|
6253
|
+
.then((response) => {
|
|
6254
|
+
if (response?.data?.data) {
|
|
6255
|
+
const academeUser = {
|
|
6256
|
+
...response.data.data,
|
|
6257
|
+
keycloakUser: getKeycloakUser(),
|
|
6258
|
+
};
|
|
6259
|
+
setCurrentUser(academeUser);
|
|
6262
6260
|
}
|
|
6263
|
-
}
|
|
6264
|
-
|
|
6265
|
-
|
|
6266
|
-
|
|
6267
|
-
|
|
6268
|
-
|
|
6269
|
-
|
|
6270
|
-
|
|
6271
|
-
|
|
6272
|
-
|
|
6273
|
-
|
|
6274
|
-
|
|
6275
|
-
|
|
6276
|
-
]);
|
|
6261
|
+
})
|
|
6262
|
+
.catch((error) => {
|
|
6263
|
+
console.error("[SecurityProvider] Error fetching user data:", error);
|
|
6264
|
+
hasFetchedUserRef.current = false;
|
|
6265
|
+
})
|
|
6266
|
+
.finally(() => {
|
|
6267
|
+
isFetchingUserRef.current = false;
|
|
6268
|
+
});
|
|
6269
|
+
}
|
|
6270
|
+
}
|
|
6271
|
+
if (!isAuthenticated && !isLoading && currentUser !== null) {
|
|
6272
|
+
setCurrentUser(null);
|
|
6273
|
+
}
|
|
6277
6274
|
const refreshUserData = React2.useCallback(async () => {
|
|
6278
6275
|
setIsRefreshing(true);
|
|
6279
6276
|
if (isAuthenticated) {
|