@furystack/rest-service
Version:
Repository implementation for FuryStack
18 lines • 639 B
JavaScript
import { AuthorizationError, isAuthorized } from '@furystack/core';
import { sleepAsync } from '@furystack/utils';
export const Authorize = (...roles) => (action) => {
return async (options) => {
try {
const authorized = await isAuthorized(options.injector, ...roles);
if (!authorized) {
await sleepAsync(Math.random() * 1000);
throw new AuthorizationError('forbidden');
}
}
catch (error) {
throw new AuthorizationError('forbidden');
}
return (await action(options));
};
};
//# sourceMappingURL=authorize.js.map