react-auth-gate 0.0.1 → 0.0.3
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PermissionsRoot.d.ts","sourceRoot":"","sources":["../../src/devtools/PermissionsRoot.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"PermissionsRoot.d.ts","sourceRoot":"","sources":["../../src/devtools/PermissionsRoot.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,EAAE,SAAS,EAAW,MAAM,OAAO,CAAC;AAIlD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD,UAAU,oBAAoB,CAAC,KAAK,GAAG,GAAG,CAAE,SAAQ,iBAAiB,CAAC,KAAK,CAAC;IAC1E,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,eAAe,CAAC,KAAK,GAAG,GAAG,EAAE,KAAK,EAAE,oBAAoB,CAAC,KAAK,CAAC,qBAkC9E"}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* Enhanced wrapper around PermissionsProvider that automatically
|
|
5
5
|
* integrates the Dev Panel in development mode.
|
|
6
6
|
*/
|
|
7
|
-
import React from 'react';
|
|
7
|
+
import React, { useMemo } from 'react';
|
|
8
8
|
import { PermissionsProvider } from '../react/PermissionsProvider';
|
|
9
9
|
import { DevPanel } from './DevPanel';
|
|
10
10
|
import { useDevRegister, useDevToolsState } from './useDevRegister';
|
|
@@ -30,10 +30,14 @@ import { useDevRegister, useDevToolsState } from './useDevRegister';
|
|
|
30
30
|
export function PermissionsRoot(props) {
|
|
31
31
|
const registerEvaluation = useDevRegister();
|
|
32
32
|
const devState = useDevToolsState();
|
|
33
|
+
// Memoize empty defaults to prevent new references on every render
|
|
34
|
+
const emptyRoles = useMemo(() => [], []);
|
|
35
|
+
const emptyPermissions = useMemo(() => [], []);
|
|
36
|
+
const emptyFlags = useMemo(() => ({}), []);
|
|
33
37
|
// Apply dev tools overrides if they exist
|
|
34
|
-
const effectiveRoles = devState.overrideRoles ?? props.roles ??
|
|
35
|
-
const effectivePermissions = devState.overridePermissions ?? props.permissions ??
|
|
36
|
-
const effectiveFlags = devState.overrideFlags ?? props.flags ??
|
|
38
|
+
const effectiveRoles = devState.overrideRoles ?? props.roles ?? emptyRoles;
|
|
39
|
+
const effectivePermissions = devState.overridePermissions ?? props.permissions ?? emptyPermissions;
|
|
40
|
+
const effectiveFlags = devState.overrideFlags ?? props.flags ?? emptyFlags;
|
|
37
41
|
// Create a key to force remount when overrides change
|
|
38
42
|
const overrideKey = JSON.stringify({
|
|
39
43
|
roles: devState.overrideRoles,
|
|
@@ -48,7 +48,7 @@ export function usePermission(check, resource, mode = 'any') {
|
|
|
48
48
|
return () => {
|
|
49
49
|
cancelled = true;
|
|
50
50
|
};
|
|
51
|
-
}, [context.evaluatePermission,
|
|
51
|
+
}, [context.evaluatePermission, check, resource, mode]);
|
|
52
52
|
return state;
|
|
53
53
|
}
|
|
54
54
|
/**
|
package/package.json
CHANGED