@nexys/user-management-sdk 0.0.10 → 0.0.12
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 +10 -13
- package/package.json +1 -1
package/dist/context.js
CHANGED
|
@@ -5,14 +5,12 @@ export const AdminContext = createContext(undefined);
|
|
|
5
5
|
const REFRESH_INTERVAL = 5 * 60 * 1000; // 5 minutes in milliseconds
|
|
6
6
|
export const AuthProvider = ({ authClient, Spinner, loginPath, }) => ({ children }) => {
|
|
7
7
|
const navigate = useNavigate();
|
|
8
|
-
const [
|
|
9
|
-
const [permissions, setPermissions] = useState([]);
|
|
10
|
-
const [locale, setLocale] = useState({ country: "US", lang: "en" });
|
|
8
|
+
const [fullProfile, setProfile] = useState(null);
|
|
11
9
|
const refreshToken = useCallback(async () => {
|
|
12
10
|
try {
|
|
13
11
|
await authClient.authRefresh();
|
|
14
|
-
const
|
|
15
|
-
setProfile(
|
|
12
|
+
const r = await authClient.getProfile();
|
|
13
|
+
setProfile(r);
|
|
16
14
|
}
|
|
17
15
|
catch (error) {
|
|
18
16
|
console.error("Token refresh failed:", error);
|
|
@@ -23,14 +21,12 @@ export const AuthProvider = ({ authClient, Spinner, loginPath, }) => ({ children
|
|
|
23
21
|
try {
|
|
24
22
|
authClient
|
|
25
23
|
.getProfile()
|
|
26
|
-
.then(
|
|
24
|
+
.then(setProfile)
|
|
27
25
|
.catch(async () => {
|
|
28
26
|
try {
|
|
29
27
|
await authClient.authRefresh();
|
|
30
|
-
const
|
|
31
|
-
setProfile(
|
|
32
|
-
setPermissions(permissions);
|
|
33
|
-
setLocale(locale);
|
|
28
|
+
const r = await authClient.getProfile();
|
|
29
|
+
setProfile(r);
|
|
34
30
|
}
|
|
35
31
|
catch (e) {
|
|
36
32
|
console.log("e1", e);
|
|
@@ -53,16 +49,17 @@ export const AuthProvider = ({ authClient, Spinner, loginPath, }) => ({ children
|
|
|
53
49
|
}, []);
|
|
54
50
|
// Set up refresh interval when profile exists
|
|
55
51
|
React.useEffect(() => {
|
|
56
|
-
if (!
|
|
52
|
+
if (!fullProfile)
|
|
57
53
|
return;
|
|
58
54
|
const intervalId = setInterval(refreshToken, REFRESH_INTERVAL);
|
|
59
55
|
return () => {
|
|
60
56
|
clearInterval(intervalId);
|
|
61
57
|
};
|
|
62
|
-
}, [
|
|
63
|
-
if (
|
|
58
|
+
}, [fullProfile, refreshToken]);
|
|
59
|
+
if (fullProfile === null) {
|
|
64
60
|
return _jsx(Spinner, {});
|
|
65
61
|
}
|
|
62
|
+
const { profile, permissions, locale } = fullProfile;
|
|
66
63
|
const logout = () => {
|
|
67
64
|
setProfile(null);
|
|
68
65
|
authClient.authLogout();
|