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 CHANGED
@@ -6039,11 +6039,12 @@ const setCookie = (name, value, domain) => {
6039
6039
  }
6040
6040
  document.cookie = cookieParts.join("; ");
6041
6041
  };
6042
- const AcademeAuthProvider = ({ realm, hubUrl, children, clientId, keycloakUrl, apiBaseUrl, skipApiUserFetch, }) => {
6042
+ const AcademeAuthProvider = ({ realm, hubUrl, children, clientId, keycloakUrl, apiBaseUrl, redirectUri, skipApiUserFetch, }) => {
6043
6043
  const oidcConfig = {
6044
6044
  authority: `${keycloakUrl}/realms/${realm}`,
6045
6045
  client_id: clientId,
6046
- redirect_uri: typeof window !== "undefined"
6046
+ redirect_uri: redirectUri ||
6047
+ typeof window !== "undefined"
6047
6048
  ? window.location.origin
6048
6049
  : process.env.NEXT_PUBLIC_REDIRECT_URI,
6049
6050
  scope: "openid profile email",
@@ -6091,8 +6092,7 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
6091
6092
  const tokenReadyPromiseRef = React2.useRef(null);
6092
6093
  const [accessToken, setAccessToken] = React2.useState(() => {
6093
6094
  const cookieToken = getAccessTokenFromCookies();
6094
- const windowToken = typeof window !== "undefined" ? window.accessToken : undefined;
6095
- return cookieToken || windowToken || auth.user?.access_token;
6095
+ return cookieToken || auth.user?.access_token;
6096
6096
  });
6097
6097
  const decodedAccessToken = React2.useMemo(() => {
6098
6098
  return accessToken ? decodeAccessToken(accessToken) : null;
@@ -6347,7 +6347,7 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
6347
6347
  }, []);
6348
6348
  // Memoizar o value do context para evitar re-renders desnecessários
6349
6349
  const contextValue = React2.useMemo(() => ({
6350
- isInitialized: !isLoading || isRefreshing || !!accessToken,
6350
+ isInitialized: !isLoading || isRefreshing,
6351
6351
  isTokenReady,
6352
6352
  user: currentUser,
6353
6353
  refreshUserData,
@@ -9344,15 +9344,13 @@ function Spinner({ className, ...props }) {
9344
9344
 
9345
9345
  const ProtectedApp = ({ children, requiredClientRoles, requiredRealmRoles, }) => {
9346
9346
  const { isInitialized, goToLogin, hasClientRole, hasRealmRole, isAuthenticated, } = useAcademeAuth();
9347
- const authenticated = isAuthenticated();
9348
- React2.useEffect(() => {
9349
- if (isInitialized && !authenticated) {
9350
- goToLogin();
9351
- }
9352
- }, [isInitialized, authenticated, goToLogin]);
9353
- if (!isInitialized || !authenticated) {
9347
+ if (!isInitialized) {
9354
9348
  return (jsxRuntime.jsx("div", { className: "flex w-screen h-screen items-center justify-center", children: jsxRuntime.jsx(Spinner, { className: "size-10 text-violet-500" }) }));
9355
9349
  }
9350
+ if (!isAuthenticated()) {
9351
+ goToLogin();
9352
+ return jsxRuntime.jsx(jsxRuntime.Fragment, {});
9353
+ }
9356
9354
  if (requiredClientRoles &&
9357
9355
  !requiredClientRoles.roles.some((role) => hasClientRole(role, requiredClientRoles.clientId))) {
9358
9356
  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" })] }));