@nexys/user-management-sdk 0.0.11 → 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.
Files changed (2) hide show
  1. package/dist/context.js +10 -13
  2. 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 [profile, setProfile] = useState(null);
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 { profile: refreshedProfile } = await authClient.getProfile();
15
- setProfile(refreshedProfile);
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(({ profile }) => setProfile(profile))
24
+ .then(setProfile)
27
25
  .catch(async () => {
28
26
  try {
29
27
  await authClient.authRefresh();
30
- const { profile, permissions, locale } = await authClient.getProfile();
31
- setProfile(profile);
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 (!profile)
52
+ if (!fullProfile)
57
53
  return;
58
54
  const intervalId = setInterval(refreshToken, REFRESH_INTERVAL);
59
55
  return () => {
60
56
  clearInterval(intervalId);
61
57
  };
62
- }, [profile, refreshToken]);
63
- if (profile === null) {
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();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nexys/user-management-sdk",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
4
4
  "private": false,
5
5
  "description": "react client/sdk that faciliates connecting to the user management",
6
6
  "main": "dist/index.js",