@riligar/auth-react 1.13.0 → 1.15.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.js CHANGED
@@ -235,7 +235,7 @@ const verifyMagicLink = async token => {
235
235
  /*--- Password Reset -----------------------------*/
236
236
  const forgotPassword = async (email, redirectTo) => {
237
237
  const redirect = redirectTo || (typeof window !== 'undefined' ? `${window.location.origin}/auth/reset-password` : '/auth/reset-password');
238
- return await api('/auth/forget-password', {
238
+ return await api('/auth/request-password-reset', {
239
239
  method: 'POST',
240
240
  body: JSON.stringify({
241
241
  email,
@@ -273,6 +273,22 @@ const resendVerification = async (email, callbackURL) => {
273
273
  const getSession = async () => {
274
274
  return await api('/auth/session');
275
275
  };
276
+ const listSessions = async () => {
277
+ return await api('/auth/list-sessions');
278
+ };
279
+ const revokeSession = async token => {
280
+ return await api('/auth/revoke-session', {
281
+ method: 'POST',
282
+ body: JSON.stringify({
283
+ token
284
+ })
285
+ });
286
+ };
287
+ const revokeOtherSessions = async () => {
288
+ return await api('/auth/revoke-other-sessions', {
289
+ method: 'POST'
290
+ });
291
+ };
276
292
 
277
293
  /*--- Application Info ----------------------------*/
278
294
  const getApplicationInfo = async () => {
@@ -324,6 +340,9 @@ const useAuthStore = zustand.create((set, get) => ({
324
340
  user: null,
325
341
  loading: true,
326
342
  error: null,
343
+ // Session management
344
+ sessions: [],
345
+ currentSessionToken: null,
327
346
  // Loading states granulares
328
347
  loadingStates: {
329
348
  signIn: false,
@@ -336,7 +355,9 @@ const useAuthStore = zustand.create((set, get) => ({
336
355
  resendVerification: false,
337
356
  updateProfile: false,
338
357
  changePassword: false,
339
- changeEmail: false
358
+ changeEmail: false,
359
+ listSessions: false,
360
+ revokeSession: false
340
361
  },
341
362
  // Application info (logo, nome, etc)
342
363
  applicationInfo: null,
@@ -637,11 +658,86 @@ const useAuthStore = zustand.create((set, get) => ({
637
658
  /* Session */
638
659
  getSession: async () => {
639
660
  try {
640
- return await getSession();
661
+ const session = await getSession();
662
+ // Store current session token for comparison
663
+ if (session?.session?.token) {
664
+ set({
665
+ currentSessionToken: session.session.token
666
+ });
667
+ }
668
+ return session;
669
+ } catch (err) {
670
+ set({
671
+ error: err
672
+ });
673
+ throw err;
674
+ }
675
+ },
676
+ listSessions: async () => {
677
+ const {
678
+ setLoading
679
+ } = get();
680
+ setLoading('listSessions', true);
681
+ set({
682
+ error: null
683
+ });
684
+ try {
685
+ const result = await listSessions();
686
+ set({
687
+ sessions: result || []
688
+ });
689
+ setLoading('listSessions', false);
690
+ return result;
691
+ } catch (err) {
692
+ set({
693
+ error: err,
694
+ sessions: []
695
+ });
696
+ setLoading('listSessions', false);
697
+ throw err;
698
+ }
699
+ },
700
+ revokeSession: async token => {
701
+ const {
702
+ setLoading,
703
+ listSessions
704
+ } = get();
705
+ setLoading('revokeSession', true);
706
+ set({
707
+ error: null
708
+ });
709
+ try {
710
+ await revokeSession(token);
711
+ // Refresh sessions list after revocation
712
+ await listSessions();
713
+ setLoading('revokeSession', false);
714
+ } catch (err) {
715
+ set({
716
+ error: err
717
+ });
718
+ setLoading('revokeSession', false);
719
+ throw err;
720
+ }
721
+ },
722
+ revokeOtherSessions: async () => {
723
+ const {
724
+ setLoading,
725
+ listSessions
726
+ } = get();
727
+ setLoading('revokeSession', true);
728
+ set({
729
+ error: null
730
+ });
731
+ try {
732
+ await revokeOtherSessions();
733
+ // Refresh sessions list after revocation
734
+ await listSessions();
735
+ setLoading('revokeSession', false);
641
736
  } catch (err) {
642
737
  set({
643
738
  error: err
644
739
  });
740
+ setLoading('revokeSession', false);
645
741
  throw err;
646
742
  }
647
743
  },
@@ -2787,9 +2883,12 @@ exports.getApplicationInfo = getApplicationInfo;
2787
2883
  exports.getCurrentUser = getCurrentUser;
2788
2884
  exports.getSession = getSession;
2789
2885
  exports.isAuthenticated = isAuthenticated;
2886
+ exports.listSessions = listSessions;
2790
2887
  exports.refreshToken = refreshToken;
2791
2888
  exports.resendVerification = resendVerification;
2792
2889
  exports.resetPassword = resetPassword;
2890
+ exports.revokeOtherSessions = revokeOtherSessions;
2891
+ exports.revokeSession = revokeSession;
2793
2892
  exports.sendMagicLink = sendMagicLink;
2794
2893
  exports.signIn = signIn;
2795
2894
  exports.signOut = signOut;