@riligar/auth-react 1.14.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.esm.js +100 -4
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +102 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -232,7 +232,7 @@ const verifyMagicLink = async token => {
|
|
|
232
232
|
/*--- Password Reset -----------------------------*/
|
|
233
233
|
const forgotPassword = async (email, redirectTo) => {
|
|
234
234
|
const redirect = redirectTo || (typeof window !== 'undefined' ? `${window.location.origin}/auth/reset-password` : '/auth/reset-password');
|
|
235
|
-
return await api('/auth/
|
|
235
|
+
return await api('/auth/request-password-reset', {
|
|
236
236
|
method: 'POST',
|
|
237
237
|
body: JSON.stringify({
|
|
238
238
|
email,
|
|
@@ -270,6 +270,22 @@ const resendVerification = async (email, callbackURL) => {
|
|
|
270
270
|
const getSession = async () => {
|
|
271
271
|
return await api('/auth/session');
|
|
272
272
|
};
|
|
273
|
+
const listSessions = async () => {
|
|
274
|
+
return await api('/auth/list-sessions');
|
|
275
|
+
};
|
|
276
|
+
const revokeSession = async token => {
|
|
277
|
+
return await api('/auth/revoke-session', {
|
|
278
|
+
method: 'POST',
|
|
279
|
+
body: JSON.stringify({
|
|
280
|
+
token
|
|
281
|
+
})
|
|
282
|
+
});
|
|
283
|
+
};
|
|
284
|
+
const revokeOtherSessions = async () => {
|
|
285
|
+
return await api('/auth/revoke-other-sessions', {
|
|
286
|
+
method: 'POST'
|
|
287
|
+
});
|
|
288
|
+
};
|
|
273
289
|
|
|
274
290
|
/*--- Application Info ----------------------------*/
|
|
275
291
|
const getApplicationInfo = async () => {
|
|
@@ -321,6 +337,9 @@ const useAuthStore = create((set, get) => ({
|
|
|
321
337
|
user: null,
|
|
322
338
|
loading: true,
|
|
323
339
|
error: null,
|
|
340
|
+
// Session management
|
|
341
|
+
sessions: [],
|
|
342
|
+
currentSessionToken: null,
|
|
324
343
|
// Loading states granulares
|
|
325
344
|
loadingStates: {
|
|
326
345
|
signIn: false,
|
|
@@ -333,7 +352,9 @@ const useAuthStore = create((set, get) => ({
|
|
|
333
352
|
resendVerification: false,
|
|
334
353
|
updateProfile: false,
|
|
335
354
|
changePassword: false,
|
|
336
|
-
changeEmail: false
|
|
355
|
+
changeEmail: false,
|
|
356
|
+
listSessions: false,
|
|
357
|
+
revokeSession: false
|
|
337
358
|
},
|
|
338
359
|
// Application info (logo, nome, etc)
|
|
339
360
|
applicationInfo: null,
|
|
@@ -634,11 +655,86 @@ const useAuthStore = create((set, get) => ({
|
|
|
634
655
|
/* Session */
|
|
635
656
|
getSession: async () => {
|
|
636
657
|
try {
|
|
637
|
-
|
|
658
|
+
const session = await getSession();
|
|
659
|
+
// Store current session token for comparison
|
|
660
|
+
if (session?.session?.token) {
|
|
661
|
+
set({
|
|
662
|
+
currentSessionToken: session.session.token
|
|
663
|
+
});
|
|
664
|
+
}
|
|
665
|
+
return session;
|
|
666
|
+
} catch (err) {
|
|
667
|
+
set({
|
|
668
|
+
error: err
|
|
669
|
+
});
|
|
670
|
+
throw err;
|
|
671
|
+
}
|
|
672
|
+
},
|
|
673
|
+
listSessions: async () => {
|
|
674
|
+
const {
|
|
675
|
+
setLoading
|
|
676
|
+
} = get();
|
|
677
|
+
setLoading('listSessions', true);
|
|
678
|
+
set({
|
|
679
|
+
error: null
|
|
680
|
+
});
|
|
681
|
+
try {
|
|
682
|
+
const result = await listSessions();
|
|
683
|
+
set({
|
|
684
|
+
sessions: result || []
|
|
685
|
+
});
|
|
686
|
+
setLoading('listSessions', false);
|
|
687
|
+
return result;
|
|
688
|
+
} catch (err) {
|
|
689
|
+
set({
|
|
690
|
+
error: err,
|
|
691
|
+
sessions: []
|
|
692
|
+
});
|
|
693
|
+
setLoading('listSessions', false);
|
|
694
|
+
throw err;
|
|
695
|
+
}
|
|
696
|
+
},
|
|
697
|
+
revokeSession: async token => {
|
|
698
|
+
const {
|
|
699
|
+
setLoading,
|
|
700
|
+
listSessions
|
|
701
|
+
} = get();
|
|
702
|
+
setLoading('revokeSession', true);
|
|
703
|
+
set({
|
|
704
|
+
error: null
|
|
705
|
+
});
|
|
706
|
+
try {
|
|
707
|
+
await revokeSession(token);
|
|
708
|
+
// Refresh sessions list after revocation
|
|
709
|
+
await listSessions();
|
|
710
|
+
setLoading('revokeSession', false);
|
|
711
|
+
} catch (err) {
|
|
712
|
+
set({
|
|
713
|
+
error: err
|
|
714
|
+
});
|
|
715
|
+
setLoading('revokeSession', false);
|
|
716
|
+
throw err;
|
|
717
|
+
}
|
|
718
|
+
},
|
|
719
|
+
revokeOtherSessions: async () => {
|
|
720
|
+
const {
|
|
721
|
+
setLoading,
|
|
722
|
+
listSessions
|
|
723
|
+
} = get();
|
|
724
|
+
setLoading('revokeSession', true);
|
|
725
|
+
set({
|
|
726
|
+
error: null
|
|
727
|
+
});
|
|
728
|
+
try {
|
|
729
|
+
await revokeOtherSessions();
|
|
730
|
+
// Refresh sessions list after revocation
|
|
731
|
+
await listSessions();
|
|
732
|
+
setLoading('revokeSession', false);
|
|
638
733
|
} catch (err) {
|
|
639
734
|
set({
|
|
640
735
|
error: err
|
|
641
736
|
});
|
|
737
|
+
setLoading('revokeSession', false);
|
|
642
738
|
throw err;
|
|
643
739
|
}
|
|
644
740
|
},
|
|
@@ -2748,5 +2844,5 @@ function SignOutButton({
|
|
|
2748
2844
|
});
|
|
2749
2845
|
}
|
|
2750
2846
|
|
|
2751
|
-
export { UserProfile as AccountModal, AuthCard, AuthLoaded, AuthLoading, AuthProvider, ForgotPassword, ForgotPassword as ForgotPasswordForm, MagicLink, MagicLinkCallback, MagicLink as MagicLinkForm, MagicLinkCallback as MagicLinkVerify, Protect, Protect as ProtectedRoute, ResetPassword, ResetPassword as ResetPasswordForm, SignIn, SignInButton, SignIn as SignInForm, SignOutButton, SignUp, SignUpButton, SignUp as SignUpForm, SignedIn, SignedOut, UserProfile, VerifyEmail, VerifyEmail as VerifyEmailCard, changeEmail, changePassword, configure, decodeJWT, forgotPassword, getApplicationInfo, getCurrentUser, getSession, isAuthenticated, refreshToken, resendVerification, resetPassword, sendMagicLink, signIn, signOut, signUp, socialRedirect, updateProfile, useApplicationLogo, useAuth, useAuthLoading, useAuthStore, useCheckToken, useEmailVerification, useMagicLink, usePasswordReset, useUser as useProfile, useSession, useSignIn, useSignOut, useSignUp, useUser, verifyEmail, verifyMagicLink };
|
|
2847
|
+
export { UserProfile as AccountModal, AuthCard, AuthLoaded, AuthLoading, AuthProvider, ForgotPassword, ForgotPassword as ForgotPasswordForm, MagicLink, MagicLinkCallback, MagicLink as MagicLinkForm, MagicLinkCallback as MagicLinkVerify, Protect, Protect as ProtectedRoute, ResetPassword, ResetPassword as ResetPasswordForm, SignIn, SignInButton, SignIn as SignInForm, SignOutButton, SignUp, SignUpButton, SignUp as SignUpForm, SignedIn, SignedOut, UserProfile, VerifyEmail, VerifyEmail as VerifyEmailCard, changeEmail, changePassword, configure, decodeJWT, forgotPassword, getApplicationInfo, getCurrentUser, getSession, isAuthenticated, listSessions, refreshToken, resendVerification, resetPassword, revokeOtherSessions, revokeSession, sendMagicLink, signIn, signOut, signUp, socialRedirect, updateProfile, useApplicationLogo, useAuth, useAuthLoading, useAuthStore, useCheckToken, useEmailVerification, useMagicLink, usePasswordReset, useUser as useProfile, useSession, useSignIn, useSignOut, useSignUp, useUser, verifyEmail, verifyMagicLink };
|
|
2752
2848
|
//# sourceMappingURL=index.esm.js.map
|