Skip to content

Commit

Permalink
Fix major bug with OR
Browse files Browse the repository at this point in the history
  • Loading branch information
utkarsh867 committed Dec 13, 2021
1 parent 40a0848 commit 14d7e73
Show file tree
Hide file tree
Showing 3 changed files with 294 additions and 6 deletions.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typegraphql-authchecker",
"version": "0.0.3",
"version": "0.1.0",
"description": "Custom authcheckers for TypeGraphql made simple.",
"author": "Utkarsh Goel",
"main": "./lib/index.js",
Expand All @@ -17,13 +17,15 @@
"@types/node": "^16.6.2",
"class-validator": "^0.13.1",
"graphql": "^15.5.1",
"ts-node-dev": "^1.1.8",
"typescript": "^4.3.5"
},
"dependencies": {
"type-graphql": "^1.1.1"
},
"scripts": {
"build": "tsc"
"build": "tsc",
"test": "tsnd --respawn tests/or.ts"
},
"peerDependencies": {
"class-validator": "^0.13.1",
Expand Down
8 changes: 4 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import "reflect-metadata";
import { AuthChecker, ResolverData } from "type-graphql";
import { ResolverData } from "type-graphql";

export type Rule<TContextType = {}> = (
D: ResolverData<TContextType>
Expand Down Expand Up @@ -40,7 +40,7 @@ function isRulesArray(rules: Rules): rules is Rules[] {
if (Array.isArray(rules)) {
const isArrayOfRules = rules.reduce((isRuleAcc, rule) => {
if (isRule(rule) || isRulesObject(rule)) {
return true;
return isRuleAcc && true;
}
return false;
}, true);
Expand Down Expand Up @@ -88,8 +88,8 @@ export const authResolver: FAuthChecker = async (
? await rules.OR.reduce<boolean | Promise<boolean>>(
async (andAcc, rule) => {
return (
andAcc ||
(await authResolver({ root, args, context, info }, rule))
(await authResolver({ root, args, context, info }, rule)) ||
andAcc
);
},
Promise.resolve(false)
Expand Down
Loading

0 comments on commit 14d7e73

Please sign in to comment.