academe-kit 0.7.7 → 0.7.8
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 +9 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +10 -7
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -6091,7 +6091,8 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
|
|
|
6091
6091
|
const tokenReadyPromiseRef = React2.useRef(null);
|
|
6092
6092
|
const [accessToken, setAccessToken] = React2.useState(() => {
|
|
6093
6093
|
const cookieToken = getAccessTokenFromCookies();
|
|
6094
|
-
|
|
6094
|
+
const windowToken = typeof window !== "undefined" ? window.accessToken : undefined;
|
|
6095
|
+
return cookieToken || windowToken || auth.user?.access_token;
|
|
6095
6096
|
});
|
|
6096
6097
|
const decodedAccessToken = React2.useMemo(() => {
|
|
6097
6098
|
return accessToken ? decodeAccessToken(accessToken) : null;
|
|
@@ -9343,13 +9344,15 @@ function Spinner({ className, ...props }) {
|
|
|
9343
9344
|
|
|
9344
9345
|
const ProtectedApp = ({ children, requiredClientRoles, requiredRealmRoles, }) => {
|
|
9345
9346
|
const { isInitialized, goToLogin, hasClientRole, hasRealmRole, isAuthenticated, } = useAcademeAuth();
|
|
9346
|
-
|
|
9347
|
+
const authenticated = isAuthenticated();
|
|
9348
|
+
React2.useEffect(() => {
|
|
9349
|
+
if (isInitialized && !authenticated) {
|
|
9350
|
+
goToLogin();
|
|
9351
|
+
}
|
|
9352
|
+
}, [isInitialized, authenticated, goToLogin]);
|
|
9353
|
+
if (!isInitialized || !authenticated) {
|
|
9347
9354
|
return (jsxRuntime.jsx("div", { className: "flex w-screen h-screen items-center justify-center", children: jsxRuntime.jsx(Spinner, { className: "size-10 text-violet-500" }) }));
|
|
9348
9355
|
}
|
|
9349
|
-
if (!isAuthenticated()) {
|
|
9350
|
-
goToLogin();
|
|
9351
|
-
return jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
|
9352
|
-
}
|
|
9353
9356
|
if (requiredClientRoles &&
|
|
9354
9357
|
!requiredClientRoles.roles.some((role) => hasClientRole(role, requiredClientRoles.clientId))) {
|
|
9355
9358
|
return (jsxRuntime.jsxs("div", { className: "flex flex-col w-screen h-screen items-center justify-center", 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.jsx(Button, { variant: "primary", className: "mt-4", size: "md", children: "Falar com o suporte" })] }));
|