academe-kit 0.7.8 → 0.8.2

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,13 +6039,13 @@ 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 || (typeof window !== "undefined"
6047
6047
  ? window.location.origin
6048
- : process.env.NEXT_PUBLIC_REDIRECT_URI,
6048
+ : process.env.NEXT_PUBLIC_REDIRECT_URI),
6049
6049
  scope: "openid profile email",
6050
6050
  onSigninCallback: () => {
6051
6051
  window.history.replaceState({}, document.title, window.location.pathname);
@@ -6091,8 +6091,7 @@ 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
- const windowToken = typeof window !== "undefined" ? window.accessToken : undefined;
6095
- return cookieToken || windowToken || auth.user?.access_token;
6094
+ return cookieToken || auth.user?.access_token;
6096
6095
  });
6097
6096
  const decodedAccessToken = React2.useMemo(() => {
6098
6097
  return accessToken ? decodeAccessToken(accessToken) : null;
@@ -6347,7 +6346,7 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
6347
6346
  }, []);
6348
6347
  // Memoizar o value do context para evitar re-renders desnecessários
6349
6348
  const contextValue = React2.useMemo(() => ({
6350
- isInitialized: !isLoading || isRefreshing || !!accessToken,
6349
+ isInitialized: !isLoading || isRefreshing,
6351
6350
  isTokenReady,
6352
6351
  user: currentUser,
6353
6352
  refreshUserData,
@@ -9344,15 +9343,13 @@ function Spinner({ className, ...props }) {
9344
9343
 
9345
9344
  const ProtectedApp = ({ children, requiredClientRoles, requiredRealmRoles, }) => {
9346
9345
  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) {
9346
+ if (!isInitialized) {
9354
9347
  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
9348
  }
9349
+ if (!isAuthenticated()) {
9350
+ goToLogin();
9351
+ return jsxRuntime.jsx(jsxRuntime.Fragment, {});
9352
+ }
9356
9353
  if (requiredClientRoles &&
9357
9354
  !requiredClientRoles.roles.some((role) => hasClientRole(role, requiredClientRoles.clientId))) {
9358
9355
  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" })] }));