11import { type H3Event } from 'h3'
22import type { AuthorizerResponse , BouncerAbility } from '../../../utils'
33import { allows as _allows , denies as _denies , authorize as _authorize , AuthorizationError } from '../../../utils'
4- import { useNitroApp , createError } from '#imports'
4+ import { createError } from '#imports'
55
66/**
77 * Allows a user to perform an action based on their role and the data.
88 */
99export async function allows < Ability extends BouncerAbility < any > > ( event : H3Event , bouncerAbility : Ability , ...args : Ability extends { original : ( user : any , ...args : infer Args ) => AuthorizerResponse } ? Args : never ) : Promise < boolean > {
10- const user = await useNitroApp ( ) . $authorization . resolveServerUser ( event )
10+ const user = await event . context . $authorization . resolveServerUser ( )
1111
1212 return _allows ( bouncerAbility , user , ...args )
1313}
@@ -16,7 +16,7 @@ export async function allows<Ability extends BouncerAbility<any>>(event: H3Event
1616 * Denies a user to perform an action based on their role and the data.
1717 */
1818export async function denies < Ability extends BouncerAbility < any > > ( event : H3Event , bouncerAbility : Ability , ...args : Ability extends { original : ( user : any , ...args : infer Args ) => AuthorizerResponse } ? Args : never ) : Promise < boolean > {
19- const user = await useNitroApp ( ) . $authorization . resolveServerUser ( event )
19+ const user = await event . context . $authorization . resolveServerUser ( )
2020
2121 return _denies ( bouncerAbility , user , ...args )
2222}
@@ -26,7 +26,7 @@ export async function denies<Ability extends BouncerAbility<any>>(event: H3Event
2626 */
2727export async function authorize < Ability extends BouncerAbility < any > > ( event : H3Event , bouncerAbility : Ability , ...args : Ability extends { original : ( user : any , ...args : infer Args ) => AuthorizerResponse } ? Args : never ) : Promise < void > {
2828 try {
29- const user = await useNitroApp ( ) . $authorization . resolveServerUser ( event )
29+ const user = await event . context . $authorization . resolveServerUser ( )
3030
3131 await _authorize ( bouncerAbility , user , ...args )
3232 }
0 commit comments