academe-kit 0.8.8 → 0.9.0

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
@@ -6032,14 +6032,14 @@ const setCookie = (name, value, domain) => {
6032
6032
  }
6033
6033
  document.cookie = cookieParts.join("; ");
6034
6034
  };
6035
+ const INITIAL_REDIRECT_URI = typeof window !== "undefined"
6036
+ ? `${window.location.origin}${window.location.pathname}`
6037
+ : undefined;
6035
6038
  const AcademeAuthProvider = ({ realm, hubUrl, children, clientId, keycloakUrl, apiBaseUrl, redirectUri, skipApiUserFetch, }) => {
6036
6039
  const oidcConfig = {
6037
6040
  authority: `${keycloakUrl}/realms/${realm}`,
6038
6041
  client_id: clientId,
6039
- redirect_uri: redirectUri ||
6040
- (typeof window !== "undefined"
6041
- ? window.location.origin
6042
- : process.env.NEXT_PUBLIC_REDIRECT_URI),
6042
+ redirect_uri: redirectUri || INITIAL_REDIRECT_URI || process.env.NEXT_PUBLIC_REDIRECT_URI,
6043
6043
  scope: "openid profile email",
6044
6044
  onSigninCallback: () => {
6045
6045
  window.history.replaceState({}, document.title, window.location.pathname);
@@ -6297,14 +6297,32 @@ const SecurityProvider = ({ apiBaseUrl = "https://stg-api.academe.com.br", skipA
6297
6297
  setIsRefreshing(false);
6298
6298
  }, [getKeycloakUser, services, skipApiUserFetch]);
6299
6299
  // --- 5. Ações de Auth ---
6300
- const signOut = useCallback(() => {
6300
+ const signOut = useCallback(async () => {
6301
6301
  console.log("[KC LOGOUT!]");
6302
6302
  setCurrentUser(null);
6303
+ setAccessToken(undefined);
6304
+ // Limpar cookie KC_FORCE_AUTH_TOKEN
6305
+ if (typeof window !== "undefined") {
6306
+ document.cookie =
6307
+ "KC_FORCE_AUTH_TOKEN=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/; domain=.academe.com.br; secure; SameSite=None";
6308
+ window.accessToken = undefined;
6309
+ }
6310
+ // Limpar storages de dados OIDC do usuário
6311
+ sessionStorage.clear();
6312
+ localStorage.removeItem(`oidc.user:${auth.settings.authority}:${auth.settings.client_id}`);
6303
6313
  auth.removeUser();
6304
- auth.signoutRedirect({
6305
- id_token_hint: auth.user?.id_token,
6306
- });
6307
6314
  auth.clearStaleState();
6315
+ // Fazer logout silencioso no Keycloak e redirecionar para login
6316
+ try {
6317
+ await auth.signoutSilent({
6318
+ id_token_hint: auth.user?.id_token,
6319
+ });
6320
+ }
6321
+ catch (error) {
6322
+ console.debug("[KC LOGOUT] Silent signout failed, redirecting to login anyway:", error);
6323
+ }
6324
+ // Redirecionar para a tela de login
6325
+ auth.signinRedirect();
6308
6326
  }, [auth]);
6309
6327
  const hasSchool = useCallback((schoolId) => {
6310
6328
  if (hasRealmRole(GLOBAL_ROLES.ADMIN_ACADEME)) {