Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bouncer functions are missing types for server #41

Open
vanekj opened this issue Jan 10, 2025 · 2 comments
Open

Bouncer functions are missing types for server #41

vanekj opened this issue Jan 10, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@vanekj
Copy link

vanekj commented Jan 10, 2025

Hello!

I found this module which I really like for my needs, but I ran into an issue with types of the bouncer functions on the server side. For example the authorize method. The method is auto-imported, but the code imported is for the client part of the application and I can't force it to the correct type where event is the first argument. I also tried to import it manually from the module itself but also with no luck.

The file on the screenshot is nested in the server/ directory.

Snímek obrazovky 2025-01-10 v 20 22 08

Sample recreation on StackBlitz,
https://stackblitz.com/edit/github-bgkk3g6m?file=server%2Fapi%2Fhello.ts

Could you please help me on that?

Thank you

@vanekj
Copy link
Author

vanekj commented Jan 13, 2025

I temporarily fixed it with patch-package module by appending Event (eg. authorizeEvent) to the bouncer functions.

nuxt-authorization+0.3.2.patch
diff --git a/node_modules/nuxt-authorization/dist/runtime/server/utils/bouncer.d.ts b/node_modules/nuxt-authorization/dist/runtime/server/utils/bouncer.d.ts
index ab46b57..585a9b2 100644
--- a/node_modules/nuxt-authorization/dist/runtime/server/utils/bouncer.d.ts
+++ b/node_modules/nuxt-authorization/dist/runtime/server/utils/bouncer.d.ts
@@ -3,12 +3,12 @@ import type { BouncerAbility, BouncerArgs } from '../../../utils/index.js';
 /**
  * Allows a user to perform an action based on their role and the data.
  */
-export declare function allows<Event extends H3Event, Ability extends BouncerAbility<any>>(event: Event, ability: Ability, ...args: BouncerArgs<Ability>): Promise<boolean>;
+export declare function allowsEvent<Event extends H3Event, Ability extends BouncerAbility<any>>(event: Event, ability: Ability, ...args: BouncerArgs<Ability>): Promise<boolean>;
 /**
  * Denies a user to perform an action based on their role and the data.
  */
-export declare function denies<Event extends H3Event, Ability extends BouncerAbility<any>>(event: Event, ability: Ability, ...args: BouncerArgs<Ability>): Promise<boolean>;
+export declare function deniesEvent<Event extends H3Event, Ability extends BouncerAbility<any>>(event: Event, ability: Ability, ...args: BouncerArgs<Ability>): Promise<boolean>;
 /**
  * Throws an error if the user is not allowed to perform an action.
  */
-export declare function authorize<Event extends H3Event, Ability extends BouncerAbility<any>>(event: Event, ability: Ability, ...args: BouncerArgs<Ability>): Promise<void>;
+export declare function authorizeEvent<Event extends H3Event, Ability extends BouncerAbility<any>>(event: Event, ability: Ability, ...args: BouncerArgs<Ability>): Promise<void>;
diff --git a/node_modules/nuxt-authorization/dist/runtime/server/utils/bouncer.js b/node_modules/nuxt-authorization/dist/runtime/server/utils/bouncer.js
index 680999c..d4fbb8d 100644
--- a/node_modules/nuxt-authorization/dist/runtime/server/utils/bouncer.js
+++ b/node_modules/nuxt-authorization/dist/runtime/server/utils/bouncer.js
@@ -1,14 +1,14 @@
 import { allows as _allows, denies as _denies, authorize as _authorize, AuthorizationError } from "../../../utils";
 import { createError } from "#imports";
-export async function allows(event, ability, ...args) {
+export async function allowsEvent(event, ability, ...args) {
   const user = await event.context.$authorization.resolveServerUser();
   return _allows(ability, user, ...args);
 }
-export async function denies(event, ability, ...args) {
+export async function deniesEvent(event, ability, ...args) {
   const user = await event.context.$authorization.resolveServerUser();
   return _denies(ability, user, ...args);
 }
-export async function authorize(event, ability, ...args) {
+export async function authorizeEvent(event, ability, ...args) {
   try {
     const user = await event.context.$authorization.resolveServerUser();
     await _authorize(ability, user, ...args);

@Barbapapazes Barbapapazes added the bug Something isn't working label Jan 26, 2025
@Barbapapazes
Copy link
Owner

Hey 👋,

I'm sorry about it but I'm unable to understand why it does not work. 🙁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants