-
-
Notifications
You must be signed in to change notification settings - Fork 1
Labels
bugSomething isn't workingSomething isn't working
Description
What happened?
Bug Description:
When a user has no permissions (empty array) or when permissions are manually passed as an empty array, wildcard patterns like * don't work as expected. This breaks the intended behavior where certain components should be visible to all users regardless of their permission status.
Expected Behavior:
<Can permission="*">Dashboard</Can>should show the Dashboard for all users, even those with no permissions- Wildcard patterns should match when user has empty permissions array
Current Behavior:
<Can permission="*">Dashboard</Can>is hidden when user has no permissions- Wildcard patterns return
falsefor users with empty permissions
Steps to Reproduce:
- Set user permissions to empty array:
[] - Use
<Can permission="*">Content</Can> - Content is not displayed
Environment:
- Package version: 1.1.1
- React/Inertia.js application
How to reproduce the bug
// ...existing code...
/**
- Check if user has a simple permission pattern (no logical operators)
*/
const checkSimplePermissionPattern = (pattern: string): boolean => {
// Handle boolean literals
if (pattern.trim() === 'true') return true;
if (pattern.trim() === 'false') return false;
// Special case: if pattern is just '*', it should match for all users
// including those with empty permissions (universal access)
if (pattern.trim() === '*') return true;
// Convert pattern to regex for simple patterns
let regexPattern = pattern
.replace(/\./g, '\\.') // Escape dots
.replace(/\*/g, '.*') // * becomes .*
.replace(/\?/g, '.'); // ? becomes .
// Ensure exact match (anchor start and end)
regexPattern = `^${regexPattern}$`;
const regex = new RegExp(regexPattern);
return userPermissions.some(permission => regex.test(permission));
};
// ...existing code...
Package Version
v1.1.1
Node.js Version
latest
React Version
latest
Inertia.js Version
latest
TypeScript Version (if applicable)
latest
Which operating systems does this happen with?
Linux
Notes
No response
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working