typegraphql-authchecker icon indicating copy to clipboard operation
typegraphql-authchecker copied to clipboard

[feature request]: add customizable default rules to all @Authorized() decoration

Open 98sean98 opened this issue 3 years ago • 0 comments

I have a specialRule authorization rule that needs to be added to all of my @Authorized(otherRules) so that this behavior

@Authorized({
  OR: [
    specialRule,
    {AND: otherRules}
  ]
})

is observed while simply writing @Authorized(otherRules) for specific typegraphql resolvers where otherRules could be some other combination of rules using AND, OR, NOT from this library.

This would avoid me from writing that same rule pattern for every @Authorized() decoration.

The usage I'm envisioning is something like, in typegraphql's buildSchema call

import {createCustomAuthChecker} from 'typegraphql-authchecker';

// passing a callback function to create a custom authchecker
// the authchecker would run this callback in lieu
const customAuthChecker = createCustomAuthChecker(
  (otherRules) => ({
    OR: [
      specialRule,
      {AND: otherRules}
    ]
  })
);

buildSchema({
  resolvers: resolvers,
  authChecker: customAuthChecker,
});

98sean98 avatar Jun 17 '22 07:06 98sean98