directus-extension-webhook-authentication
Version:
Directus Flows Operation to check webhook authorization
2 lines (1 loc) • 615 B
JavaScript
const e=[],t=[],a=[{name:"check-auth",config:{id:"flows-check-auth",handler:({level:e},{accountability:t})=>{if(!("admin"!==e||t&&t.user&&t.admin))throw new Error("Unauthenticated.");if(!("user"!==e||t&&t.user))throw new Error("Unauthenticated.");return!0}}},{name:"check-perms",config:{id:"flows-check-perms",handler:async({collection:e},{services:t,database:a,getSchema:c,accountability:r})=>{const{ItemsService:n}=t,i=new n(e,{knex:a,schema:await c(r),accountability:r});try{await i.readByQuery({limit:1})}catch{throw new Error("Unauthenticated.")}return!0}}}];export{t as endpoints,e as hooks,a as operations};