Guard.authorizePipe #132
dipankarmaikap
started this conversation in
General
Replies: 1 comment
-
If I make the ability file like this then Its showing my custom error. Don't know if this is ideal way to do this. import db, { Prisma } from "db"
import { GuardBuilder } from "@blitz-guard/core"
type ExtendedResourceTypes = "project" | "choice" | Prisma.ModelName
type ExtendedAbilityTypes = "send email"
const Guard = GuardBuilder<ExtendedResourceTypes, ExtendedAbilityTypes>(
async (ctx, { can, cannot }) => {
cannot("manage", "all").reason("You are not ADMIN!")
cannot("manage", "project")
if (ctx.session.$isAuthorized()) {
can("manage", "project")
cannot("delete", "project", async (_args) => {
return (await db.project.count({ where: { userId: ctx.session.userId } })) !== 1
}).reason("You are not The owner of this project")
cannot("update", "question", async (_args) => {
return (await db.project.count({ where: { userId: ctx.session.userId } })) !== 1
}).reason("You are not The owner of this project")
}
}
)
export default Guard |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is there any way I can add custom error message.? Currently It throws
AuthorizationError GUARD: UNAUTHORIZED
Beta Was this translation helpful? Give feedback.
All reactions