0.0.15 • Published 4 years ago
typestack-authorizer v0.0.15
��# Typestack Authorizer
Indevelopment
Opinionated authorizer using the power of typescript annotation to annotate ClassType
and Methods
,
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)