refactor(#10): eliminate redundant DB role lookups in AdminGuard, consolidate duplicate JWT guards#39
Open
d3vobed wants to merge 1 commit into
Conversation
…dminGuard, fix role case bug, consolidate duplicate JWT guards The AdminGuard already read request.user.role from the JWT payload and did NOT query the database — the root concern of the issue was already addressed. This PR cleans up remaining structural issues: Fixes: - Fix @roles('admin') -> @roles('ADMIN') case mismatch in admin.controller.ts so RolesGuard actually matches the uppercase enum value - Remove unused Passport JwtStrategy in src/auth/ (orphaned, never registered in any module) - Augment users/guards/jwt-auth.guard.ts to inject ConfigService and pass the secret explicitly to jwt.verify(), matching the pattern of the auth/ variant - Remove duplicate auth/jwt-auth.guard.ts; all modules now import the canonical version from users/guards/ - Fix pre-existing type error in campaigns.service.spec.ts where the it.each table passed undefined without a type annotation All 7 existing guard/service test suites pass unchanged (44 tests). 9 new tests added for standalone coverage. Closes OrbitChainLabs#10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The AdminGuard already read
request.user.rolefrom the JWT payload and did not query the database — the root concern from the issue was already resolved in the existing code. This PR addresses the remaining structural issues: a role-case bug that brokeRolesGuard, duplicate JWT guard implementations, orphaned dead code, and a pre-existing TypeScript error in tests.Changes
Fixes
@Roles(admin)→@Roles(ADMIN)inadmin.controller.ts— the valueadmin(lowercase) never matched theUserRole.ADMINenum, makingRolesGuarda no-op for admin endpointsJwtStrategy(src/auth/jwt.strategy.ts) — a Passport strategy that was never registered in any module; dead code eliminatedauth/jwt-auth.guard.ts— both guards did the same thing; all 8 importing modules now reference the canonical version atusers/guards/jwt-auth.guard.tsConfigService— the canonical guard readsJWT_SECRETfrom config explicitly, consistent with the removed auth versionTest improvements
campaigns.service.spec.ts—it.eachtable passedundefinedwithout a type annotation, causingtsc --noEmitto failTesting
tsc --noEmit)Closes #10