Skip to content

Releases: ntgussoni/blitz-guard

v0.4.1

29 Jul 19:32
Compare
Choose a tag to compare

💥 Major Changes

  • Reasons: Give your rules custom a custom message
...

const Guard = GuardBuilder<ExtendedResourceTypes, ExtendedAbilityTypes>(
  async (ctx, { can, cannot }) => {
	cannot('manage', 'all')

	can("create", "article")
	cannot("create", "article").reason("Because I say so")

...

const { can, reason } = Guard.can("create", "article",{},{})
console.log(can) // false
console.log(reason) // "Because I say so"

This introduces a breaking change if you are using Guard.can

// Before
- const can = Guard.can("create", "article",{},{})
// now
+ const { can, reason } = Guard.can("create", "article",{},{})

At the same time, if you are using the getAbility hook, the return type now is an object instead of a boolean

...
const [[canCreateComment, canDeleteComment], { isLoading }] = useQuery(getAbility, [
  ["create", "comment"],
  ["delete", "comment" /* args */],
])

console.log(canCreateComment.can) // true
console.log(canCreateComment.reason) // "some reason"

console.log(canDeleteComment.can) // false
console.log(canDeleteComment.reason) // "some reason"
// Before
- const [[canCreateComment], { isLoading }] = useQuery(getAbility, [
- console.log(canCreateComment) // true

// Now
+ console.log(canCreateComment.can) // true
+ console.log(canCreateComment.reason) // "some reason"

🚀 Minor Changes

  • Adds Guard.authorizePipe
...
resolver.pipe(
  resolver.zod(CreateProject),
  Guard.authorizePipe("create", "project"),
...

If you are using pipes in your queries or mutations you can use Guard.authorizePipe as shown in the example. If the authorization fails it will throw an AuthorizationError

See usage here: https://ntgussoni.github.io/blitz-guard/docs/secure-your-endpoints/#guardauthorizepipe

Internal Meta Changes

  • Updates docs
  • Update of dependencies

v0.3.1

01 Feb 20:13
Compare
Choose a tag to compare

🐞 Patches

  • Removes resource sanitization: 767c36d

Internal Meta Changes

  • Makes warning about how empty ability works: aa39769
  • Adds how to contribute documentation Updates docs colors and adds favicon: 8c01805
  • Updates docs to enforce cannot('manage', 'all'): 0d6420b
  • Merge pull request #17 from ntgussoni/add-fail-to-sample-test: 49057c2

v0.3.0

27 Jan 22:43
Compare
Choose a tag to compare

🔥 Major Changes

  • Updates the signature of Guard.can to match authenticate: a838b16

Internal Meta Changes

  • Updates example prisma version: b0f3d2a
  • Adds middleware to example app: 4c0819e
  • Improves docs and adds testing section: 54af305

v0.2.1

27 Jan 18:37
Compare
Choose a tag to compare

🐞 Patches

  • Updates types destination path: eb9b884

v0.2.0

27 Jan 16:29
Compare
Choose a tag to compare

🚀 Major Changes

  • Refactored library to improve type handling Removes useGuard in favor of a simple useQuery hook Ability is the main entry file now: 42a3222
  • Updates typescript configuration for incremental updates Updates example app to latest blitz version: 7bb315c

Internal Meta Changes

v0.1.12

23 Jan 13:48
Compare
Choose a tag to compare

🐞 Patches

v0.1.6

23 Jan 09:57
Compare
Choose a tag to compare

Initial release