academe-kit 0.7.8 → 0.8.1
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 +10 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +11 -13
- package/dist/index.esm.js.map +1 -1
- package/dist/types/context/SecurityProvider/types.d.ts +1 -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;
|
package/dist/index.esm.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsx,
|
|
1
|
+
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
2
2
|
import React2, { forwardRef, createElement, createContext, useContext, useState, useRef, useMemo, useEffect, useCallback } from 'react';
|
|
3
3
|
|
|
4
4
|
function r(e){var t,f,n="";if("string"==typeof e||"number"==typeof e)n+=e;else if("object"==typeof e)if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(f=r(e[t]))&&(n&&(n+=" "),n+=f);}else for(f in e)e[f]&&(n&&(n+=" "),n+=f);return n}function clsx(){for(var e,t,f=0,n="",o=arguments.length;f<o;f++)(e=arguments[f])&&(t=r(e))&&(n&&(n+=" "),n+=t);return n}
|
|
@@ -6037,11 +6037,12 @@ const setCookie = (name, value, domain) => {
|
|
|
6037
6037
|
}
|
|
6038
6038
|
document.cookie = cookieParts.join("; ");
|
|
6039
6039
|
};
|
|
6040
|
-
const AcademeAuthProvider = ({ realm, hubUrl, children, clientId, keycloakUrl, apiBaseUrl, skipApiUserFetch, }) => {
|
|
6040
|
+
const AcademeAuthProvider = ({ realm, hubUrl, children, clientId, keycloakUrl, apiBaseUrl, redirectUri, skipApiUserFetch, }) => {
|
|
6041
6041
|
const oidcConfig = {
|
|
6042
6042
|
authority: `${keycloakUrl}/realms/${realm}`,
|
|
6043
6043
|
client_id: clientId,
|
|
6044
|
-
redirect_uri:
|
|
6044
|
+
redirect_uri: redirectUri ||
|
|
6045
|
+
typeof window !== "undefined"
|
|
6045
6046
|
? window.location.origin
|
|
6046
6047
|
: process.env.NEXT_PUBLIC_REDIRECT_URI,
|
|
6047
6048
|
scope: "openid profile email",
|
|
@@ -6089,8 +6090,7 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
|
|
|
6089
6090
|
const tokenReadyPromiseRef = useRef(null);
|
|
6090
6091
|
const [accessToken, setAccessToken] = useState(() => {
|
|
6091
6092
|
const cookieToken = getAccessTokenFromCookies();
|
|
6092
|
-
|
|
6093
|
-
return cookieToken || windowToken || auth.user?.access_token;
|
|
6093
|
+
return cookieToken || auth.user?.access_token;
|
|
6094
6094
|
});
|
|
6095
6095
|
const decodedAccessToken = useMemo(() => {
|
|
6096
6096
|
return accessToken ? decodeAccessToken(accessToken) : null;
|
|
@@ -6345,7 +6345,7 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
|
|
|
6345
6345
|
}, []);
|
|
6346
6346
|
// Memoizar o value do context para evitar re-renders desnecessários
|
|
6347
6347
|
const contextValue = useMemo(() => ({
|
|
6348
|
-
isInitialized: !isLoading || isRefreshing
|
|
6348
|
+
isInitialized: !isLoading || isRefreshing,
|
|
6349
6349
|
isTokenReady,
|
|
6350
6350
|
user: currentUser,
|
|
6351
6351
|
refreshUserData,
|
|
@@ -9342,15 +9342,13 @@ function Spinner({ className, ...props }) {
|
|
|
9342
9342
|
|
|
9343
9343
|
const ProtectedApp = ({ children, requiredClientRoles, requiredRealmRoles, }) => {
|
|
9344
9344
|
const { isInitialized, goToLogin, hasClientRole, hasRealmRole, isAuthenticated, } = useAcademeAuth();
|
|
9345
|
-
|
|
9346
|
-
useEffect(() => {
|
|
9347
|
-
if (isInitialized && !authenticated) {
|
|
9348
|
-
goToLogin();
|
|
9349
|
-
}
|
|
9350
|
-
}, [isInitialized, authenticated, goToLogin]);
|
|
9351
|
-
if (!isInitialized || !authenticated) {
|
|
9345
|
+
if (!isInitialized) {
|
|
9352
9346
|
return (jsx("div", { className: "flex w-screen h-screen items-center justify-center", children: jsx(Spinner, { className: "size-10 text-violet-500" }) }));
|
|
9353
9347
|
}
|
|
9348
|
+
if (!isAuthenticated()) {
|
|
9349
|
+
goToLogin();
|
|
9350
|
+
return jsx(Fragment, {});
|
|
9351
|
+
}
|
|
9354
9352
|
if (requiredClientRoles &&
|
|
9355
9353
|
!requiredClientRoles.roles.some((role) => hasClientRole(role, requiredClientRoles.clientId))) {
|
|
9356
9354
|
return (jsxs("div", { className: "flex flex-col w-screen h-screen items-center justify-center", 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." }), jsx(Button, { variant: "primary", className: "mt-4", size: "md", children: "Falar com o suporte" })] }));
|