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

[EVOLUTION] - Store auth information on CrudRequest object #11

Closed
gantispam opened this issue Jan 9, 2023 · 5 comments
Closed

[EVOLUTION] - Store auth information on CrudRequest object #11

gantispam opened this issue Jan 9, 2023 · 5 comments

Comments

@gantispam
Copy link

Hi.

First of all : thinks you for your fork ! ;-)


  • Subject :

    • CrudRequest object is pass between Controller and Service. But on this object we dont store any context informations as authenticate user for exemple : (this is nice to have auth user object on service (stored on native Request object))
  • Do you think it's possible to store extra informations on CrudRequest object and in particular auth. user?

    • Note :
      • Store native NestJs Request object is not possible : risk of producing strange case with singleton service (switch to Scope=Request by nestJs), but store auth user information seen to be possible.
      • Auth user can be found on native Request object with nesths-crud configuration auth. sample configuration ;
CrudConfigService.load({
      params: {
       [...]
      },
      auth: {
        property: 'user',
      },
[...]
* CurdRequest interface can became : 
export interface CrudRequest {
    parsed: ParsedRequestParams;
    options: CrudRequestOptions;
    auth: any; // according to configuration
    extra: any; // any params for business logic
}
@zaro
Copy link
Member

zaro commented Mar 8, 2023

What is the use case for that?

Isn't it enough getting the user from the request object?

@gantispam
Copy link
Author

Sorry i think my issue is not very clear, i think there is 2 linkeds subjects :

  • Subject 1. Nestjs-crud ask to Map "auth.property". it's pity to dont use this informations for hydrate auth informations on CrudRequest.
    • Exemple of use case :
    • check some additional sécurité rules of AuthGuard directory on services.
    • add author informations on log on services
    • use this object to add some custom business rules (it's my principal let's motivation, i often add some business instructions on CrudRequest.option according to user'auth informations, as role for exemple)
    • Prevent/simplify nestjs pattern that remove singleton pattern on service

This feature give a usefulll "helper" for développer.

  • Subject 2 (linked with subject 1) : If i dont do a mistake all attributs on CrudRequest object is interpreted by nestjs-crud. That feature can be obvious if we need to pass some custom/business param for exemple (throw exception because this custom param is not know on entity ..). Exemple of use case (stupide case 😁 there is a lot of use case more interresting ) :
    • If i want to get my entity A and add some custom attribut on entity for count the number of relationship B, it's usefulll to add "extra.b.count" on request and do my custom request directly on service.

This feature give more flexibility on request process.

@zaro
Copy link
Member

zaro commented Mar 8, 2023

I see, it makes sense yes.

If you are willing to make a PR I will review and merge it. Else we might introduce when we need it, right now we have no immediate need for this functionality but I can see it ( especially the extra parameters) being very useful.

gantispam pushed a commit to gantispam/crud that referenced this issue Mar 13, 2023
gantispam pushed a commit to gantispam/crud that referenced this issue Mar 13, 2023
@gantispam
Copy link
Author

Hi, the PR is here for your code review #13

thx.

gantispam pushed a commit to gantispam/crud that referenced this issue Mar 15, 2023
gantispam pushed a commit to gantispam/crud that referenced this issue Mar 15, 2023
zaro added a commit that referenced this issue Mar 16, 2023
#11 Store auth information on CrudRequest object
@gantispam
Copy link
Author

Feature is implemented on v5.2.3

https://github.com/gid-oss/dataui-nestjs-crud/tree/v5.2.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants