What it does
A wildcard permission grants all permissions with a matching prefix. Grant posts.* to give a user all permissions starting with posts. at once: posts.create, posts.edit, posts.delete, etc.
When to use it
Use wildcards when:
- Admins need broad access —
admin.*or*for everything - Whole subsystems — grant
posts.*to a content editor - You don't want to list every permission — 10 permissions per role is tedious
Wildcards keep your config readable and reduce boilerplate.
How it works
- Grant a wildcard permission:
adminrole gets*(everything) orposts.*(all posts) - Check normally:
await perms.user(42).can("posts.edit") - permly expands the wildcard and checks if the permission matches
Wildcards are stored as strings in the database. permly expands them at check time.
Examples
import { perms, setupPermissions } from "./permly.js";
await setupPermissions();
// Admin has the * wildcard (all permissions)
await perms.user(99).assignRole("admin");
// Can admin do anything?
const canCreate = await perms.user(99).can("posts.create");
const canDelete = await perms.user(99).can("comments.delete");
console.log(canCreate); // true
console.log(canDelete); // true
import { perms, setupPermissions } from "./permly.js";
await setupPermissions();
await perms.user(99).assignRole("admin");
const canCreate: boolean = await perms.user(99).can("posts.create");
const canDelete: boolean = await perms.user(99).can("comments.delete");
console.log(canCreate);
console.log(canDelete);
Namespace wildcards
Grant all permissions in a namespace:
import { perms, setupPermissions } from "./permly.js";
await setupPermissions();
// Editor has posts.* (all post permissions)
await perms.user(5).assignRole("editor");
// Can editor do all post actions?
const canCreate = await perms.user(5).can("posts.create");
const canEdit = await perms.user(5).can("posts.edit");
const canDelete = await perms.user(5).can("posts.delete");
console.log(canCreate); // true
console.log(canEdit); // true
console.log(canDelete); // true
import { perms, setupPermissions } from "./permly.js";
await setupPermissions();
await perms.user(5).assignRole("editor");
const canCreate: boolean = await perms.user(5).can("posts.create");
const canEdit: boolean = await perms.user(5).can("posts.edit");
const canDelete: boolean = await perms.user(5).can("posts.delete");
console.log(canCreate);
console.log(canEdit);
console.log(canDelete);
Wildcard matching
Wildcards match by prefix. posts.* matches posts.create but NOT posts_edit (wrong separator):
import { perms, setupPermissions } from "./permly.js";
await setupPermissions();
// User has admin.* (not admin.config.*)
await perms.user(10).givePermission("admin.*");
// These match
const canSettings = await perms.user(10).can("admin.settings");
const canUsers = await perms.user(10).can("admin.users");
// This does NOT match (different prefix)
const canPosts = await perms.user(10).can("posts.create");
console.log(canSettings); // true
console.log(canUsers); // true
console.log(canPosts); // false
import { perms, setupPermissions } from "./permly.js";
await setupPermissions();
await perms.user(10).givePermission("admin.*");
const canSettings: boolean = await perms.user(10).can("admin.settings");
const canPosts: boolean = await perms.user(10).can("posts.create");
console.log(canSettings);
console.log(canPosts);
Be careful with wildcards
Wildcards are powerful but can be overly broad. Avoid * for regular users—only use it for admins or trusted roles.
Common mistakes
Forgetting the dot — posts* does NOT match posts.create (need posts.*). Always use the separator.
Over-using wildcards — If you have 100 permissions and grant * to half your users, your config is too coarse-grained. Use specific roles instead.
Misunderstanding prefix matching — admin.* matches admin.settings but not admin_settings (wrong separator). Match is by prefix, not pattern.
Related pages
- Permissions — Core concepts
- Roles — How roles work
- Checking Permissions — Runtime checks