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.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, jsxs, Fragment } from 'react/jsx-runtime';
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,13 +6037,13 @@ 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: typeof window !== "undefined"
6044
+ redirect_uri: redirectUri || (typeof window !== "undefined"
6045
6045
  ? window.location.origin
6046
- : process.env.NEXT_PUBLIC_REDIRECT_URI,
6046
+ : process.env.NEXT_PUBLIC_REDIRECT_URI),
6047
6047
  scope: "openid profile email",
6048
6048
  onSigninCallback: () => {
6049
6049
  window.history.replaceState({}, document.title, window.location.pathname);
@@ -6089,8 +6089,7 @@ 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
- const windowToken = typeof window !== "undefined" ? window.accessToken : undefined;
6093
- return cookieToken || windowToken || auth.user?.access_token;
6092
+ return cookieToken || auth.user?.access_token;
6094
6093
  });
6095
6094
  const decodedAccessToken = useMemo(() => {
6096
6095
  return accessToken ? decodeAccessToken(accessToken) : null;
@@ -6345,7 +6344,7 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
6345
6344
  }, []);
6346
6345
  // Memoizar o value do context para evitar re-renders desnecessários
6347
6346
  const contextValue = useMemo(() => ({
6348
- isInitialized: !isLoading || isRefreshing || !!accessToken,
6347
+ isInitialized: !isLoading || isRefreshing,
6349
6348
  isTokenReady,
6350
6349
  user: currentUser,
6351
6350
  refreshUserData,
@@ -9342,15 +9341,13 @@ function Spinner({ className, ...props }) {
9342
9341
 
9343
9342
  const ProtectedApp = ({ children, requiredClientRoles, requiredRealmRoles, }) => {
9344
9343
  const { isInitialized, goToLogin, hasClientRole, hasRealmRole, isAuthenticated, } = useAcademeAuth();
9345
- const authenticated = isAuthenticated();
9346
- useEffect(() => {
9347
- if (isInitialized && !authenticated) {
9348
- goToLogin();
9349
- }
9350
- }, [isInitialized, authenticated, goToLogin]);
9351
- if (!isInitialized || !authenticated) {
9344
+ if (!isInitialized) {
9352
9345
  return (jsx("div", { className: "flex w-screen h-screen items-center justify-center", children: jsx(Spinner, { className: "size-10 text-violet-500" }) }));
9353
9346
  }
9347
+ if (!isAuthenticated()) {
9348
+ goToLogin();
9349
+ return jsx(Fragment, {});
9350
+ }
9354
9351
  if (requiredClientRoles &&
9355
9352
  !requiredClientRoles.roles.some((role) => hasClientRole(role, requiredClientRoles.clientId))) {
9356
9353
  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" })] }));