Skip to content

Instantly share code, notes, and snippets.

@ktutnik
Last active May 27, 2019 02:16
Show Gist options
  • Select an option

  • Save ktutnik/dfcad44bc33efe5744c5c846c8fceaee to your computer and use it in GitHub Desktop.

Select an option

Save ktutnik/dfcad44bc33efe5744c5c846c8fceaee to your computer and use it in GitHub Desktop.
// custom authorization decorator
function ownerOrAdmin() {
return authorize.custom(async ({ role, user, parameters }) => {
return role.some(x => x === "Admin") || parameters[0] === user.userId
})
}
export class UsersController {
@ownerOrAdmin()
@route.patch(":id")
modify(id:number, user:User){
// implementation
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment