File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -77,12 +77,29 @@ export function usePermissions() {
7777
7878/**
7979 * Convenience hook to check if user has a specific permission
80+ * Supports both array and object-based permission formats
8081 */
8182export function useHasPermission ( permission : string ) {
8283 const { permissions, isPending } = usePermissions ( ) ;
8384
85+ const hasPermission = ( ( ) => {
86+ if ( ! permissions ) return false ;
87+
88+ // Array format: ['user.read', 'user.write']
89+ if ( Array . isArray ( permissions ) ) {
90+ return permissions . includes ( permission ) ;
91+ }
92+
93+ // Object format: { 'user.read': true, 'user.write': false }
94+ if ( typeof permissions === 'object' ) {
95+ return permissions [ permission ] === true ;
96+ }
97+
98+ return false ;
99+ } ) ( ) ;
100+
84101 return {
85- hasPermission : permissions ?. includes ?. ( permission ) ?? false ,
102+ hasPermission,
86103 isPending,
87104 } ;
88105}
You can’t perform that action at this time.
0 commit comments