Skip to content

Instantly share code, notes, and snippets.

@nabiltntn
Created December 28, 2018 13:32
Show Gist options
  • Select an option

  • Save nabiltntn/240be21aa6bcffead835acc8c4a846a4 to your computer and use it in GitHub Desktop.

Select an option

Save nabiltntn/240be21aa6bcffead835acc8c4a846a4 to your computer and use it in GitHub Desktop.
// For resolvers that require authenticated users with ADMIN role
export const isAdminResolver = (resolver, trackDetails) =>
isAuthenticated.createResolver((root, args, context) => {
if (![Constants.UsersRolesToIds.ADMIN, Constants.UsersRolesToIds.SUPER_ADMIN]
.includes(context.user.role)) {
throw new Errors.ForbiddenError();
}
return executeWithTracking(resolver, root, args, context, trackDetails);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment