@riligar/auth-react 1.19.0 → 1.20.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/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Auth React
2
2
 
3
+ [![npm version](https://img.shields.io/npm/v/@riligar/auth-react.svg)](https://www.npmjs.com/package/@riligar/auth-react)
4
+ [![npm downloads](https://img.shields.io/npm/dm/@riligar/auth-react.svg)](https://www.npmjs.com/package/@riligar/auth-react)
5
+ [![license](https://img.shields.io/npm/l/@riligar/auth-react.svg)](https://www.npmjs.com/package/@riligar/auth-react)
6
+
3
7
  Auth SDK for React with JWT and JWKS.
4
8
 
5
9
  ## Installation
package/dist/index.esm.js CHANGED
@@ -99,17 +99,8 @@ function setStoredToken(token) {
99
99
  function handleAuthResponse(result) {
100
100
  // Tenta encontrar o token em vários lugares possíveis
101
101
  const token = result.token || result.session?.token || result.session?.sessionToken;
102
- console.log('[AuthSDK] Handling Auth Response:', {
103
- hasToken: !!result.token,
104
- hasSessionToken: !!result.session?.token,
105
- hasSessionSessionToken: !!result.session?.sessionToken,
106
- extractedToken: token
107
- });
108
102
  if (token) {
109
- console.log('[AuthSDK] Saving token to storage');
110
103
  setStoredToken(token);
111
- } else {
112
- console.warn('[AuthSDK] No token found in response', result);
113
104
  }
114
105
  return result;
115
106
  }
@@ -359,7 +350,7 @@ const useAuthStore = create((set, get) => ({
359
350
  changePassword: false,
360
351
  changeEmail: false,
361
352
  listSessions: false,
362
- revokeSession: false
353
+ revokeSession: null // null or sessionId being revoked
363
354
  },
364
355
  // Application info (logo, nome, etc)
365
356
  applicationInfo: null,
@@ -703,40 +694,35 @@ const useAuthStore = create((set, get) => ({
703
694
  sessions,
704
695
  signOut
705
696
  } = get();
706
- setLoading('revokeSession', true);
697
+ setLoading('revokeSession', sessionId);
707
698
  set({
708
699
  error: null
709
700
  });
710
701
  try {
711
- console.log('[AuthStore] Revoking session:', {
712
- targetId: sessionId,
713
- currentId: currentSession?.id,
714
- totalSessions: sessions.length
715
- });
716
-
717
702
  // Detect if current session OR last remaining session
718
703
  const isCurrent = sessionId === currentSession?.id;
719
704
  const isLast = sessions.length === 1 && sessions[0].id === sessionId;
720
705
 
721
706
  // Se for a sessão atual ou a última, faz logout normal
722
707
  if (isCurrent || isLast) {
723
- console.log('[AuthStore] Revoking current/last session -> Executing signOut');
724
708
  await signOut();
725
709
  // signOut já limpa loading states e erros no finally, mas
726
710
  // como estamos dentro do fluxo deste método, garantimos:
727
- setLoading('revokeSession', false);
711
+ setLoading('revokeSession', null);
728
712
  return;
729
713
  }
730
714
  await revokeSession(sessionId);
731
715
 
732
- // NÃO atualiza a lista automaticamente - se for a sessão atual,
733
- // listSessions() vai falhar com 401. O componente decide se quer atualizar.
734
- setLoading('revokeSession', false);
716
+ // Remove a sessão revogada da lista local
717
+ set(state => ({
718
+ sessions: state.sessions.filter(s => s.id !== sessionId)
719
+ }));
720
+ setLoading('revokeSession', null);
735
721
  } catch (err) {
736
722
  set({
737
723
  error: err
738
724
  });
739
- setLoading('revokeSession', false);
725
+ setLoading('revokeSession', null);
740
726
  throw err;
741
727
  }
742
728
  },
@@ -745,7 +731,7 @@ const useAuthStore = create((set, get) => ({
745
731
  setLoading,
746
732
  listSessions
747
733
  } = get();
748
- setLoading('revokeSession', true);
734
+ setLoading('revokeSession', 'all');
749
735
  set({
750
736
  error: null
751
737
  });
@@ -753,12 +739,12 @@ const useAuthStore = create((set, get) => ({
753
739
  await revokeOtherSessions();
754
740
  // Refresh sessions list after revocation
755
741
  await listSessions();
756
- setLoading('revokeSession', false);
742
+ setLoading('revokeSession', null);
757
743
  } catch (err) {
758
744
  set({
759
745
  error: err
760
746
  });
761
- setLoading('revokeSession', false);
747
+ setLoading('revokeSession', null);
762
748
  throw err;
763
749
  }
764
750
  },
@@ -2927,7 +2913,7 @@ function UserProfile({
2927
2913
  color: "red",
2928
2914
  size: "xs",
2929
2915
  onClick: () => handleRevokeSession(sessionItem.id),
2930
- loading: loadingRevokeSession,
2916
+ loading: loadingRevokeSession === sessionItem.id,
2931
2917
  leftSection: /*#__PURE__*/jsx(IconLogout, {
2932
2918
  size: 14
2933
2919
  }),
@@ -2943,7 +2929,7 @@ function UserProfile({
2943
2929
  color: "red",
2944
2930
  size: "xs",
2945
2931
  onClick: handleRevokeOtherSessions,
2946
- loading: loadingRevokeSession,
2932
+ loading: loadingRevokeSession === 'all',
2947
2933
  leftSection: /*#__PURE__*/jsx(IconLogout, {
2948
2934
  size: 14
2949
2935
  }),