Skip to content

Instantly share code, notes, and snippets.

@davorg
Created January 18, 2026 09:33
Show Gist options
  • Select an option

  • Save davorg/9893686ce3b4d44aea9b0d1114c1179c to your computer and use it in GitHub Desktop.

Select an option

Save davorg/9893686ce3b4d44aea9b0d1114c1179c to your computer and use it in GitHub Desktop.
class User {
constructor({ isActive, role, isSuspended } = {}) {
this.isActive = isActive;
this.role = role;
this.role = role;
this.isSuspended = isSuspended;
}
canAccessAdmin() {
return this.isActive && this.role === "admin" && !this.isSuspended;
}
grantAccess() {
if (!this.canAccessAdmin()) {
throw new Error("User is not permitted to access admin features");
}
// perform the access-granting work here
}
}
// usage
try {
user.grantAccess();
} catch (err) {
// handle / log / show error
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment