academe-kit 0.8.5 → 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 +58 -66
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.esm.js +58 -66
- package/dist/index.esm.js.map +1 -1
- package/dist/types/context/SecurityProvider/types.d.ts +2 -0
- package/package.json +1 -1
- package/dist/index.js +0 -8724
- package/dist/index.js.map +0 -1
- package/dist/types/services/CourseLogService.d.ts +0 -12258
- /package/dist/types/services/{userService.d.ts → UserService.d.ts} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -6028,24 +6028,20 @@ const getAccessTokenFromCookies = () => {
|
|
|
6028
6028
|
const setCookie = (name, value, domain) => {
|
|
6029
6029
|
if (typeof window === "undefined")
|
|
6030
6030
|
return;
|
|
6031
|
-
const cookieParts = [
|
|
6032
|
-
`${name}=${value}`,
|
|
6033
|
-
"path=/",
|
|
6034
|
-
"secure",
|
|
6035
|
-
"SameSite=None",
|
|
6036
|
-
];
|
|
6031
|
+
const cookieParts = [`${name}=${value}`, "path=/", "secure", "SameSite=None"];
|
|
6037
6032
|
{
|
|
6038
6033
|
cookieParts.push(`domain=${domain}`);
|
|
6039
6034
|
}
|
|
6040
6035
|
document.cookie = cookieParts.join("; ");
|
|
6041
6036
|
};
|
|
6042
|
-
const AcademeAuthProvider = ({ realm, hubUrl, children, clientId, keycloakUrl, apiBaseUrl, skipApiUserFetch, }) => {
|
|
6037
|
+
const AcademeAuthProvider = ({ realm, hubUrl, children, clientId, keycloakUrl, apiBaseUrl, redirectUri, skipApiUserFetch, }) => {
|
|
6043
6038
|
const oidcConfig = {
|
|
6044
6039
|
authority: `${keycloakUrl}/realms/${realm}`,
|
|
6045
6040
|
client_id: clientId,
|
|
6046
|
-
redirect_uri:
|
|
6047
|
-
|
|
6048
|
-
|
|
6041
|
+
redirect_uri: redirectUri ||
|
|
6042
|
+
(typeof window !== "undefined"
|
|
6043
|
+
? window.location.origin
|
|
6044
|
+
: process.env.NEXT_PUBLIC_REDIRECT_URI),
|
|
6049
6045
|
scope: "openid profile email",
|
|
6050
6046
|
onSigninCallback: () => {
|
|
6051
6047
|
window.history.replaceState({}, document.title, window.location.pathname);
|
|
@@ -6100,7 +6096,7 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
|
|
|
6100
6096
|
const isAuthenticated = auth.isAuthenticated || !!accessToken;
|
|
6101
6097
|
const isLoading = auth.isLoading;
|
|
6102
6098
|
const activeNavigator = auth.activeNavigator;
|
|
6103
|
-
|
|
6099
|
+
auth.user?.profile;
|
|
6104
6100
|
const currentTokenRef = React2.useRef(undefined);
|
|
6105
6101
|
// Efeito para sincronizar o token do auth com o state
|
|
6106
6102
|
// e também verificar cookies periodicamente
|
|
@@ -6130,9 +6126,7 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
|
|
|
6130
6126
|
return;
|
|
6131
6127
|
const handlePostMessage = (event) => {
|
|
6132
6128
|
try {
|
|
6133
|
-
const data = typeof event.data === "string"
|
|
6134
|
-
? JSON.parse(event.data)
|
|
6135
|
-
: event.data;
|
|
6129
|
+
const data = typeof event.data === "string" ? JSON.parse(event.data) : event.data;
|
|
6136
6130
|
if (data?.type === "KC_TOKEN_UPDATE" && data?.payload?.accessToken) {
|
|
6137
6131
|
const newToken = data.payload.accessToken;
|
|
6138
6132
|
console.log("[SecurityProvider] Received KC_TOKEN_UPDATE via postMessage");
|
|
@@ -6140,8 +6134,7 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
|
|
|
6140
6134
|
setAccessToken(newToken);
|
|
6141
6135
|
}
|
|
6142
6136
|
}
|
|
6143
|
-
catch {
|
|
6144
|
-
}
|
|
6137
|
+
catch { }
|
|
6145
6138
|
};
|
|
6146
6139
|
window.addEventListener("message", handlePostMessage);
|
|
6147
6140
|
return () => {
|
|
@@ -6211,14 +6204,14 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
|
|
|
6211
6204
|
}
|
|
6212
6205
|
}, [accessToken, isLoading, isAuthenticated]);
|
|
6213
6206
|
const getKeycloakUser = React2.useCallback(() => {
|
|
6214
|
-
const profile = userProfile;
|
|
6215
6207
|
return {
|
|
6216
|
-
email:
|
|
6217
|
-
name:
|
|
6218
|
-
lastName:
|
|
6208
|
+
email: decodedAccessToken?.email || "",
|
|
6209
|
+
name: decodedAccessToken?.given_name || "",
|
|
6210
|
+
lastName: decodedAccessToken?.family_name || "",
|
|
6219
6211
|
avatar_url: decodedAccessToken?.avatar_url,
|
|
6212
|
+
tm_token: decodedAccessToken?.tm_token,
|
|
6220
6213
|
};
|
|
6221
|
-
}, [
|
|
6214
|
+
}, [decodedAccessToken]);
|
|
6222
6215
|
const hasRealmRole = React2.useCallback((role) => {
|
|
6223
6216
|
return decodedAccessToken?.realm_access?.roles?.includes(role) ?? false;
|
|
6224
6217
|
}, [decodedAccessToken]);
|
|
@@ -6234,51 +6227,50 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
|
|
|
6234
6227
|
return Object.values(decodedAccessToken.resource_access).some((resource) => resource.roles?.includes(role));
|
|
6235
6228
|
}, [decodedAccessToken]);
|
|
6236
6229
|
// --- 4. Fetch de Dados do Usuário (Backend) ---
|
|
6237
|
-
|
|
6238
|
-
|
|
6239
|
-
|
|
6240
|
-
|
|
6241
|
-
|
|
6242
|
-
|
|
6243
|
-
|
|
6244
|
-
|
|
6245
|
-
|
|
6246
|
-
|
|
6247
|
-
|
|
6248
|
-
|
|
6249
|
-
|
|
6250
|
-
|
|
6251
|
-
|
|
6252
|
-
|
|
6253
|
-
const academeUser = {
|
|
6254
|
-
...response.data.data,
|
|
6255
|
-
keycloakUser: getKeycloakUser(),
|
|
6256
|
-
};
|
|
6257
|
-
setCurrentUser(academeUser);
|
|
6258
|
-
}
|
|
6259
|
-
}
|
|
6260
|
-
catch (error) {
|
|
6261
|
-
console.error("[SecurityProvider] Error fetching user data:", error);
|
|
6262
|
-
}
|
|
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 || "" });
|
|
6263
6246
|
}
|
|
6264
|
-
|
|
6265
|
-
|
|
6266
|
-
|
|
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);
|
|
6267
6260
|
}
|
|
6268
|
-
}
|
|
6269
|
-
|
|
6270
|
-
|
|
6271
|
-
|
|
6272
|
-
|
|
6273
|
-
|
|
6274
|
-
|
|
6275
|
-
|
|
6276
|
-
|
|
6277
|
-
|
|
6278
|
-
|
|
6279
|
-
|
|
6280
|
-
|
|
6281
|
-
]);
|
|
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
|
+
}
|
|
6282
6274
|
const refreshUserData = React2.useCallback(async () => {
|
|
6283
6275
|
setIsRefreshing(true);
|
|
6284
6276
|
if (isAuthenticated) {
|
|
@@ -9352,11 +9344,11 @@ const ProtectedApp = ({ children, requiredClientRoles, requiredRealmRoles, }) =>
|
|
|
9352
9344
|
}
|
|
9353
9345
|
if (requiredClientRoles &&
|
|
9354
9346
|
!requiredClientRoles.roles.some((role) => hasClientRole(role, requiredClientRoles.clientId))) {
|
|
9355
|
-
return (jsxRuntime.jsxs("div", { className: "flex flex-col w-screen h-screen items-center justify-center bg-background", children: [jsxRuntime.jsx(CircleAlert, { className: "size-10 text-primary " }), jsxRuntime.jsx("h1", { className: "text-2xl font-bold mt-4 text-center", children: "Oops, voc\u00EA n\u00E3o tem permiss\u00E3o para acessar aqui." }), jsxRuntime.jsx("span", { className: "text-center", children: "Se voc\u00EA acredita que isso \u00E9 um erro, entre em contato com o suporte." }), jsxRuntime.jsxs("div", { className: "flex gap-3 mt-4", children: [jsxRuntime.jsx(Button, { variant: "primary", size: "md", children: "Falar com o suporte" }), jsxRuntime.jsx(Button, { variant: "outline", size: "md", onClick: signOut, children: "
|
|
9347
|
+
return (jsxRuntime.jsxs("div", { className: "flex flex-col w-screen h-screen items-center justify-center bg-background", children: [jsxRuntime.jsx(CircleAlert, { className: "size-10 text-primary " }), jsxRuntime.jsx("h1", { className: "text-2xl font-bold mt-4 text-center", children: "Oops, voc\u00EA n\u00E3o tem permiss\u00E3o para acessar aqui." }), jsxRuntime.jsx("span", { className: "text-center", children: "Se voc\u00EA acredita que isso \u00E9 um erro, entre em contato com o suporte." }), jsxRuntime.jsxs("div", { className: "flex gap-3 mt-4", children: [jsxRuntime.jsx(Button, { variant: "primary", size: "md", children: "Falar com o suporte" }), jsxRuntime.jsx(Button, { variant: "outline", size: "md", onClick: signOut, children: "Sair da conta" })] })] }));
|
|
9356
9348
|
}
|
|
9357
9349
|
if (requiredRealmRoles &&
|
|
9358
9350
|
!requiredRealmRoles?.some((role) => hasRealmRole(role))) {
|
|
9359
|
-
return (jsxRuntime.jsxs("div", { className: "flex flex-col w-screen h-screen items-center justify-center bg-background", children: [jsxRuntime.jsx(CircleAlert, { className: "size-10 text-primary " }), jsxRuntime.jsx("h1", { className: "text-2xl font-bold mt-4 text-center", children: "Oops, voc\u00EA n\u00E3o tem permiss\u00E3o para acessar aqui." }), jsxRuntime.jsx("span", { className: "text-center", children: "Se voc\u00EA acredita que isso \u00E9 um erro, entre em contato com o suporte." }), jsxRuntime.jsxs("div", { className: "flex gap-3 mt-4", children: [jsxRuntime.jsx(Button, { variant: "primary", size: "md", children: "Falar com o suporte" }), jsxRuntime.jsx(Button, { variant: "outline", size: "md", onClick: signOut, children: "
|
|
9351
|
+
return (jsxRuntime.jsxs("div", { className: "flex flex-col w-screen h-screen items-center justify-center bg-background", children: [jsxRuntime.jsx(CircleAlert, { className: "size-10 text-primary " }), jsxRuntime.jsx("h1", { className: "text-2xl font-bold mt-4 text-center", children: "Oops, voc\u00EA n\u00E3o tem permiss\u00E3o para acessar aqui." }), jsxRuntime.jsx("span", { className: "text-center", children: "Se voc\u00EA acredita que isso \u00E9 um erro, entre em contato com o suporte." }), jsxRuntime.jsxs("div", { className: "flex gap-3 mt-4", children: [jsxRuntime.jsx(Button, { variant: "primary", size: "md", children: "Falar com o suporte" }), jsxRuntime.jsx(Button, { variant: "outline", size: "md", onClick: signOut, children: "Sair da conta" })] })] }));
|
|
9360
9352
|
}
|
|
9361
9353
|
return children;
|
|
9362
9354
|
};
|