wycliffepeart / typestack-authorizer

Authorization using annotations

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Typestack Authorizer

Indevelopment

Opinionated authorizer using the power of typescript annotation to annotate ClassType and Methods,

Installation

Authorizer

Allow Access

Deny Access

Type Graphql Middleware

Installation

npm install typestack-authorizer

Authorizer

@Authorizer()
export class PostResolver { }

Allow Access

@Allow()
createPost(){ }

Deny Access

@Deny()
deletePost(){ }

Type Graphql Global Middleware

import { NextFn } from 'type-graphql'
import { Effect, AuthorizerData } from 'typestack-authorizer'


async function authorizer({ authorizer }: AuthorizerData, next: NextFn){
  
  if (authorizer.effect === Effect.ALLOW) {
  
    return await next()
  
  } else if (authorizer.effect === Effect.DENY) {
    
    throw new Error('Unauthorized')
  
  } else {

    // else
  
  }

}

registerTypeGraphqlGlobalMiddleware(authorizer)

About

Authorization using annotations


Languages

Language:JavaScript 87.5%Language:TypeScript 12.5%