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.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
1
+ import { jsx, jsxs, Fragment } 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}
@@ -6089,7 +6089,8 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
6089
6089
  const tokenReadyPromiseRef = useRef(null);
6090
6090
  const [accessToken, setAccessToken] = useState(() => {
6091
6091
  const cookieToken = getAccessTokenFromCookies();
6092
- return cookieToken || auth.user?.access_token;
6092
+ const windowToken = typeof window !== "undefined" ? window.accessToken : undefined;
6093
+ return cookieToken || windowToken || auth.user?.access_token;
6093
6094
  });
6094
6095
  const decodedAccessToken = useMemo(() => {
6095
6096
  return accessToken ? decodeAccessToken(accessToken) : null;
@@ -9341,13 +9342,15 @@ function Spinner({ className, ...props }) {
9341
9342
 
9342
9343
  const ProtectedApp = ({ children, requiredClientRoles, requiredRealmRoles, }) => {
9343
9344
  const { isInitialized, goToLogin, hasClientRole, hasRealmRole, isAuthenticated, } = useAcademeAuth();
9344
- if (!isInitialized) {
9345
+ const authenticated = isAuthenticated();
9346
+ useEffect(() => {
9347
+ if (isInitialized && !authenticated) {
9348
+ goToLogin();
9349
+ }
9350
+ }, [isInitialized, authenticated, goToLogin]);
9351
+ if (!isInitialized || !authenticated) {
9345
9352
  return (jsx("div", { className: "flex w-screen h-screen items-center justify-center", children: jsx(Spinner, { className: "size-10 text-violet-500" }) }));
9346
9353
  }
9347
- if (!isAuthenticated()) {
9348
- goToLogin();
9349
- return jsx(Fragment, {});
9350
- }
9351
9354
  if (requiredClientRoles &&
9352
9355
  !requiredClientRoles.roles.some((role) => hasClientRole(role, requiredClientRoles.clientId))) {
9353
9356
  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" })] }));