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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conflict when using Guard with the same class name #3841

Closed
xstevenyung opened this issue Jan 15, 2020 · 2 comments
Closed

Conflict when using Guard with the same class name #3841

xstevenyung opened this issue Jan 15, 2020 · 2 comments
Labels
needs triage This issue has not been looked into

Comments

@xstevenyung
Copy link

Hello there 馃憢

Thanks a lot for Nest.js, I'm really loving the work that you guys are putting out there !

Bug Report

Current behaviour

If we use two different guards using the same class name but different files, only the first guard met will be recognise and used (cf. repo link below).

Input Code

Repo: https://github.com/stvnyung/nest-guard-issue
Specific commit implementing the issue: https://github.com/stvnyung/nest-guard-issue/commit/7040292e033574b80ee79aeef3f6b5c21d1611d6

In the repo, you can see CommentController uses src/comment/is-owner.guard.ts which will always fails as it returns false.

But because, in app.module.ts we declare our controller in the order controllers: [ AppController, PostController, CommentController ], only the guard src/post/is-owner.guard.ts is actually used.

You can see that all the request will be successful on http://localhost:3000/post and http://localhost:3000/comment.

Expected behavior

Nest.js should differentiate both guards even if they use the same name.

Possible Solution

At least I think it should throw an error if we use two different guard with the same class name.

Environment


Nest version: 6.10.14
@xstevenyung xstevenyung added the needs triage This issue has not been looked into label Jan 15, 2020
@kamilmysliwiec
Copy link
Member

Hey @stvnyung!

This happens when you have guards (or any enhancers) with the same name registered in 1 module. We're tracking this issue here #789

Aside note: having classes with the exact same name in one module should be considered as a bad practice.

@lock
Copy link

lock bot commented Apr 15, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Apr 15, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs triage This issue has not been looked into
Projects
None yet
Development

No branches or pull requests

2 participants