import { Hook , HookDecorator , HttpResponseForbidden , HttpResponseRedirect , HttpResponseUnauthorized , } from '@foal/core' ; export param { string } perm param { { redirect ? : string } } options param { string | undefined } options . redirect returns { HookDecorator } export function PermissionRequired ( perm , options = { } ) { return Hook ( ctx => { if ( ! ctx . user ) { if ( options . redirect ) { return new HttpResponseRedirect ( options . redirect ) ; } return new HttpResponseUnauthorized ( ) ; } if ( ! ctx . user . hasPerm ( perm ) ) { return new HttpResponseForbidden ( ) ; } } ) ; }