@lark-apaas/auth-sdk 0.1.0-alpha.30 → 0.1.0-alpha.31

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.
@@ -9,7 +9,7 @@ const AbilityContext = /*#__PURE__*/ createContext(createAbility({
9
9
  }));
10
10
  const AuthStateContext = /*#__PURE__*/ createContext(null);
11
11
  function AuthProvider({ children, config }) {
12
- const [ability] = useState(()=>createAbility({}));
12
+ const [ability, setAbility] = useState(()=>createAbility({}));
13
13
  const [isLoading, setIsLoading] = useState(false);
14
14
  const [error, setError] = useState(null);
15
15
  const [client] = useState(()=>new PermissionClient(config?.permissionApi));
@@ -18,9 +18,10 @@ function AuthProvider({ children, config }) {
18
18
  setError(null);
19
19
  try {
20
20
  const data = await client.fetchPermissions();
21
- updateAbility(ability, {
21
+ const newAbility = createAbility({
22
22
  roles: data.roles
23
23
  });
24
+ setAbility(newAbility);
24
25
  config?.onSuccess?.(data);
25
26
  } catch (err) {
26
27
  const error = err instanceof Error ? err : new Error(String(err));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/auth-sdk",
3
- "version": "0.1.0-alpha.30",
3
+ "version": "0.1.0-alpha.31",
4
4
  "description": "基于 CASL 的前端鉴权 SDK",
5
5
  "types": "./lib/index.d.ts",
6
6
  "main": "./lib/index.js",