@nexys/user-management-sdk 0.0.2 → 0.0.4
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/context.js +22 -1
- package/dist/type.js +6 -0
- package/package.json +1 -1
package/dist/context.js
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import React, { createContext, useContext, useState } from "react";
|
|
2
|
+
import React, { createContext, useCallback, useContext, useState, } from "react";
|
|
3
3
|
import { useNavigate } from "react-router-dom";
|
|
4
4
|
export const AdminContext = createContext(undefined);
|
|
5
|
+
const REFRESH_INTERVAL = 5 * 60 * 1000; // 5 minutes in milliseconds
|
|
5
6
|
export const AuthProvider = ({ authClient, Spinner, loginPath, }) => ({ children }) => {
|
|
6
7
|
const navigate = useNavigate();
|
|
7
8
|
const [profile, setProfile] = useState(null);
|
|
9
|
+
const refreshToken = useCallback(async () => {
|
|
10
|
+
try {
|
|
11
|
+
await authClient.authRefresh();
|
|
12
|
+
const { profile: refreshedProfile } = await authClient.getProfile();
|
|
13
|
+
setProfile(refreshedProfile);
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
console.error("Token refresh failed:", error);
|
|
17
|
+
//redirectToLogin("Your session is no longer active, you were redirected");
|
|
18
|
+
}
|
|
19
|
+
}, [authClient]);
|
|
8
20
|
React.useEffect(() => {
|
|
9
21
|
try {
|
|
10
22
|
authClient
|
|
@@ -38,6 +50,15 @@ export const AuthProvider = ({ authClient, Spinner, loginPath, }) => ({ children
|
|
|
38
50
|
if (profile === null) {
|
|
39
51
|
return _jsx(Spinner, {});
|
|
40
52
|
}
|
|
53
|
+
// Set up refresh interval when profile exists
|
|
54
|
+
React.useEffect(() => {
|
|
55
|
+
if (!profile)
|
|
56
|
+
return;
|
|
57
|
+
const intervalId = setInterval(refreshToken, REFRESH_INTERVAL);
|
|
58
|
+
return () => {
|
|
59
|
+
clearInterval(intervalId);
|
|
60
|
+
};
|
|
61
|
+
}, [profile, refreshToken]);
|
|
41
62
|
const logout = () => {
|
|
42
63
|
setProfile(null);
|
|
43
64
|
authClient.authLogout();
|
package/dist/type.js
CHANGED
|
@@ -10,3 +10,9 @@ export const ssoAvailable = [
|
|
|
10
10
|
"github",
|
|
11
11
|
"google",
|
|
12
12
|
];
|
|
13
|
+
export var Permission;
|
|
14
|
+
(function (Permission) {
|
|
15
|
+
Permission[Permission["app"] = 1] = "app";
|
|
16
|
+
Permission[Permission["admin"] = 2] = "admin";
|
|
17
|
+
Permission[Permission["superadmin"] = 3] = "superadmin";
|
|
18
|
+
})(Permission || (Permission = {}));
|