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.d.ts
CHANGED
|
@@ -20671,6 +20671,7 @@ type AcademeKeycloakContextProps = {
|
|
|
20671
20671
|
initOptions?: KeycloakInitOptions;
|
|
20672
20672
|
skipApiUserFetch?: boolean;
|
|
20673
20673
|
children: React.ReactElement;
|
|
20674
|
+
redirectUri?: string;
|
|
20674
20675
|
};
|
|
20675
20676
|
type SecurityProviderProps = {
|
|
20676
20677
|
hubUrl?: string;
|
|
@@ -20683,6 +20684,7 @@ type KeycloakUser = {
|
|
|
20683
20684
|
lastName: string;
|
|
20684
20685
|
email: string;
|
|
20685
20686
|
avatar_url?: string;
|
|
20687
|
+
tm_token?: string;
|
|
20686
20688
|
};
|
|
20687
20689
|
type AcademeUser = User & {
|
|
20688
20690
|
keycloakUser?: KeycloakUser;
|
package/dist/index.esm.js
CHANGED
|
@@ -6026,24 +6026,20 @@ const getAccessTokenFromCookies = () => {
|
|
|
6026
6026
|
const setCookie = (name, value, domain) => {
|
|
6027
6027
|
if (typeof window === "undefined")
|
|
6028
6028
|
return;
|
|
6029
|
-
const cookieParts = [
|
|
6030
|
-
`${name}=${value}`,
|
|
6031
|
-
"path=/",
|
|
6032
|
-
"secure",
|
|
6033
|
-
"SameSite=None",
|
|
6034
|
-
];
|
|
6029
|
+
const cookieParts = [`${name}=${value}`, "path=/", "secure", "SameSite=None"];
|
|
6035
6030
|
{
|
|
6036
6031
|
cookieParts.push(`domain=${domain}`);
|
|
6037
6032
|
}
|
|
6038
6033
|
document.cookie = cookieParts.join("; ");
|
|
6039
6034
|
};
|
|
6040
|
-
const AcademeAuthProvider = ({ realm, hubUrl, children, clientId, keycloakUrl, apiBaseUrl, skipApiUserFetch, }) => {
|
|
6035
|
+
const AcademeAuthProvider = ({ realm, hubUrl, children, clientId, keycloakUrl, apiBaseUrl, redirectUri, skipApiUserFetch, }) => {
|
|
6041
6036
|
const oidcConfig = {
|
|
6042
6037
|
authority: `${keycloakUrl}/realms/${realm}`,
|
|
6043
6038
|
client_id: clientId,
|
|
6044
|
-
redirect_uri:
|
|
6045
|
-
|
|
6046
|
-
|
|
6039
|
+
redirect_uri: redirectUri ||
|
|
6040
|
+
(typeof window !== "undefined"
|
|
6041
|
+
? window.location.origin
|
|
6042
|
+
: process.env.NEXT_PUBLIC_REDIRECT_URI),
|
|
6047
6043
|
scope: "openid profile email",
|
|
6048
6044
|
onSigninCallback: () => {
|
|
6049
6045
|
window.history.replaceState({}, document.title, window.location.pathname);
|
|
@@ -6098,7 +6094,7 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
|
|
|
6098
6094
|
const isAuthenticated = auth.isAuthenticated || !!accessToken;
|
|
6099
6095
|
const isLoading = auth.isLoading;
|
|
6100
6096
|
const activeNavigator = auth.activeNavigator;
|
|
6101
|
-
|
|
6097
|
+
auth.user?.profile;
|
|
6102
6098
|
const currentTokenRef = useRef(undefined);
|
|
6103
6099
|
// Efeito para sincronizar o token do auth com o state
|
|
6104
6100
|
// e também verificar cookies periodicamente
|
|
@@ -6128,9 +6124,7 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
|
|
|
6128
6124
|
return;
|
|
6129
6125
|
const handlePostMessage = (event) => {
|
|
6130
6126
|
try {
|
|
6131
|
-
const data = typeof event.data === "string"
|
|
6132
|
-
? JSON.parse(event.data)
|
|
6133
|
-
: event.data;
|
|
6127
|
+
const data = typeof event.data === "string" ? JSON.parse(event.data) : event.data;
|
|
6134
6128
|
if (data?.type === "KC_TOKEN_UPDATE" && data?.payload?.accessToken) {
|
|
6135
6129
|
const newToken = data.payload.accessToken;
|
|
6136
6130
|
console.log("[SecurityProvider] Received KC_TOKEN_UPDATE via postMessage");
|
|
@@ -6138,8 +6132,7 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
|
|
|
6138
6132
|
setAccessToken(newToken);
|
|
6139
6133
|
}
|
|
6140
6134
|
}
|
|
6141
|
-
catch {
|
|
6142
|
-
}
|
|
6135
|
+
catch { }
|
|
6143
6136
|
};
|
|
6144
6137
|
window.addEventListener("message", handlePostMessage);
|
|
6145
6138
|
return () => {
|
|
@@ -6209,14 +6202,14 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
|
|
|
6209
6202
|
}
|
|
6210
6203
|
}, [accessToken, isLoading, isAuthenticated]);
|
|
6211
6204
|
const getKeycloakUser = useCallback(() => {
|
|
6212
|
-
const profile = userProfile;
|
|
6213
6205
|
return {
|
|
6214
|
-
email:
|
|
6215
|
-
name:
|
|
6216
|
-
lastName:
|
|
6206
|
+
email: decodedAccessToken?.email || "",
|
|
6207
|
+
name: decodedAccessToken?.given_name || "",
|
|
6208
|
+
lastName: decodedAccessToken?.family_name || "",
|
|
6217
6209
|
avatar_url: decodedAccessToken?.avatar_url,
|
|
6210
|
+
tm_token: decodedAccessToken?.tm_token,
|
|
6218
6211
|
};
|
|
6219
|
-
}, [
|
|
6212
|
+
}, [decodedAccessToken]);
|
|
6220
6213
|
const hasRealmRole = useCallback((role) => {
|
|
6221
6214
|
return decodedAccessToken?.realm_access?.roles?.includes(role) ?? false;
|
|
6222
6215
|
}, [decodedAccessToken]);
|
|
@@ -6232,51 +6225,50 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
|
|
|
6232
6225
|
return Object.values(decodedAccessToken.resource_access).some((resource) => resource.roles?.includes(role));
|
|
6233
6226
|
}, [decodedAccessToken]);
|
|
6234
6227
|
// --- 4. Fetch de Dados do Usuário (Backend) ---
|
|
6235
|
-
useEffect(
|
|
6236
|
-
|
|
6237
|
-
|
|
6238
|
-
|
|
6239
|
-
|
|
6240
|
-
|
|
6241
|
-
|
|
6242
|
-
|
|
6243
|
-
|
|
6244
|
-
|
|
6245
|
-
|
|
6246
|
-
|
|
6247
|
-
|
|
6248
|
-
|
|
6249
|
-
|
|
6250
|
-
|
|
6251
|
-
const academeUser = {
|
|
6252
|
-
...response.data.data,
|
|
6253
|
-
keycloakUser: getKeycloakUser(),
|
|
6254
|
-
};
|
|
6255
|
-
setCurrentUser(academeUser);
|
|
6256
|
-
}
|
|
6257
|
-
}
|
|
6258
|
-
catch (error) {
|
|
6259
|
-
console.error("[SecurityProvider] Error fetching user data:", error);
|
|
6260
|
-
}
|
|
6228
|
+
// Refs para controlar fetch sem depender de useEffect (componente pode desmontar antes dos efeitos executarem)
|
|
6229
|
+
const hasFetchedUserRef = useRef(false);
|
|
6230
|
+
const isFetchingUserRef = useRef(false);
|
|
6231
|
+
if (!isAuthenticated) {
|
|
6232
|
+
hasFetchedUserRef.current = false;
|
|
6233
|
+
}
|
|
6234
|
+
if (isAuthenticated &&
|
|
6235
|
+
!hasFetchedUserRef.current &&
|
|
6236
|
+
!isFetchingUserRef.current) {
|
|
6237
|
+
if (skipApiUserFetch) {
|
|
6238
|
+
if (decodedAccessToken) {
|
|
6239
|
+
hasFetchedUserRef.current = true;
|
|
6240
|
+
const academeUser = {
|
|
6241
|
+
keycloakUser: getKeycloakUser(),
|
|
6242
|
+
};
|
|
6243
|
+
setCurrentUser({ ...academeUser, id: userProfileSub || "" });
|
|
6261
6244
|
}
|
|
6262
|
-
|
|
6263
|
-
|
|
6264
|
-
|
|
6245
|
+
}
|
|
6246
|
+
else {
|
|
6247
|
+
hasFetchedUserRef.current = true;
|
|
6248
|
+
isFetchingUserRef.current = true;
|
|
6249
|
+
services.user
|
|
6250
|
+
.getMe()
|
|
6251
|
+
.then((response) => {
|
|
6252
|
+
if (response?.data?.data) {
|
|
6253
|
+
const academeUser = {
|
|
6254
|
+
...response.data.data,
|
|
6255
|
+
keycloakUser: getKeycloakUser(),
|
|
6256
|
+
};
|
|
6257
|
+
setCurrentUser(academeUser);
|
|
6265
6258
|
}
|
|
6266
|
-
}
|
|
6267
|
-
|
|
6268
|
-
|
|
6269
|
-
|
|
6270
|
-
|
|
6271
|
-
|
|
6272
|
-
|
|
6273
|
-
|
|
6274
|
-
|
|
6275
|
-
|
|
6276
|
-
|
|
6277
|
-
|
|
6278
|
-
|
|
6279
|
-
]);
|
|
6259
|
+
})
|
|
6260
|
+
.catch((error) => {
|
|
6261
|
+
console.error("[SecurityProvider] Error fetching user data:", error);
|
|
6262
|
+
hasFetchedUserRef.current = false;
|
|
6263
|
+
})
|
|
6264
|
+
.finally(() => {
|
|
6265
|
+
isFetchingUserRef.current = false;
|
|
6266
|
+
});
|
|
6267
|
+
}
|
|
6268
|
+
}
|
|
6269
|
+
if (!isAuthenticated && !isLoading && currentUser !== null) {
|
|
6270
|
+
setCurrentUser(null);
|
|
6271
|
+
}
|
|
6280
6272
|
const refreshUserData = useCallback(async () => {
|
|
6281
6273
|
setIsRefreshing(true);
|
|
6282
6274
|
if (isAuthenticated) {
|
|
@@ -9350,11 +9342,11 @@ const ProtectedApp = ({ children, requiredClientRoles, requiredRealmRoles, }) =>
|
|
|
9350
9342
|
}
|
|
9351
9343
|
if (requiredClientRoles &&
|
|
9352
9344
|
!requiredClientRoles.roles.some((role) => hasClientRole(role, requiredClientRoles.clientId))) {
|
|
9353
|
-
return (jsxs("div", { className: "flex flex-col w-screen h-screen items-center justify-center bg-background", children: [jsx(CircleAlert, { className: "size-10 text-primary " }), jsx("h1", { className: "text-2xl font-bold mt-4 text-center", children: "Oops, voc\u00EA n\u00E3o tem permiss\u00E3o para acessar aqui." }), jsx("span", { className: "text-center", children: "Se voc\u00EA acredita que isso \u00E9 um erro, entre em contato com o suporte." }), jsxs("div", { className: "flex gap-3 mt-4", children: [jsx(Button, { variant: "primary", size: "md", children: "Falar com o suporte" }), jsx(Button, { variant: "outline", size: "md", onClick: signOut, children: "
|
|
9345
|
+
return (jsxs("div", { className: "flex flex-col w-screen h-screen items-center justify-center bg-background", children: [jsx(CircleAlert, { className: "size-10 text-primary " }), jsx("h1", { className: "text-2xl font-bold mt-4 text-center", children: "Oops, voc\u00EA n\u00E3o tem permiss\u00E3o para acessar aqui." }), jsx("span", { className: "text-center", children: "Se voc\u00EA acredita que isso \u00E9 um erro, entre em contato com o suporte." }), jsxs("div", { className: "flex gap-3 mt-4", children: [jsx(Button, { variant: "primary", size: "md", children: "Falar com o suporte" }), jsx(Button, { variant: "outline", size: "md", onClick: signOut, children: "Sair da conta" })] })] }));
|
|
9354
9346
|
}
|
|
9355
9347
|
if (requiredRealmRoles &&
|
|
9356
9348
|
!requiredRealmRoles?.some((role) => hasRealmRole(role))) {
|
|
9357
|
-
return (jsxs("div", { className: "flex flex-col w-screen h-screen items-center justify-center bg-background", children: [jsx(CircleAlert, { className: "size-10 text-primary " }), jsx("h1", { className: "text-2xl font-bold mt-4 text-center", children: "Oops, voc\u00EA n\u00E3o tem permiss\u00E3o para acessar aqui." }), jsx("span", { className: "text-center", children: "Se voc\u00EA acredita que isso \u00E9 um erro, entre em contato com o suporte." }), jsxs("div", { className: "flex gap-3 mt-4", children: [jsx(Button, { variant: "primary", size: "md", children: "Falar com o suporte" }), jsx(Button, { variant: "outline", size: "md", onClick: signOut, children: "
|
|
9349
|
+
return (jsxs("div", { className: "flex flex-col w-screen h-screen items-center justify-center bg-background", children: [jsx(CircleAlert, { className: "size-10 text-primary " }), jsx("h1", { className: "text-2xl font-bold mt-4 text-center", children: "Oops, voc\u00EA n\u00E3o tem permiss\u00E3o para acessar aqui." }), jsx("span", { className: "text-center", children: "Se voc\u00EA acredita que isso \u00E9 um erro, entre em contato com o suporte." }), jsxs("div", { className: "flex gap-3 mt-4", children: [jsx(Button, { variant: "primary", size: "md", children: "Falar com o suporte" }), jsx(Button, { variant: "outline", size: "md", onClick: signOut, children: "Sair da conta" })] })] }));
|
|
9358
9350
|
}
|
|
9359
9351
|
return children;
|
|
9360
9352
|
};
|