-
Notifications
You must be signed in to change notification settings - Fork 59
ready for merge #351
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
ready for merge #351
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,31 @@ | ||
| import { Injectable, CanActivate, ExecutionContext } from '@nestjs/common'; | ||
| import { Reflector } from '@nestjs/core'; | ||
| import { UserRole } from '../../users/entities/user.entity'; | ||
| import { InjectRepository } from '@nestjs/typeorm'; | ||
| import { Repository } from 'typeorm'; | ||
| import { User, UserRole } from '../../users/entities/user.entity'; | ||
|
|
||
| @Injectable() | ||
| export class RolesGuard implements CanActivate { | ||
| constructor(private reflector: Reflector) {} | ||
| constructor( | ||
| private reflector: Reflector, | ||
| @InjectRepository(User) private readonly userRepository: Repository<User>, | ||
| ) {} | ||
|
Comment on lines
+9
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "RolesGuard references in modules:"
rg -n -C2 '\bRolesGuard\b' backend/src --glob '**/*.module.ts' || true
echo
echo "RolesGuard use sites:"
rg -n -C2 '@UseGuards\([^)]*\bRolesGuard\b' backend/src --type=ts || true
echo
echo "AuthModule wiring:"
sed -n '1,200p' backend/src/auth/auth.module.tsRepository: OlufunbiIK/tip-tune Length of output: 6982 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "=== Finding RolesGuard file ==="
fd -type f -name '*roles.guard*' backend/src
echo
echo "=== RolesGuard implementation ==="
cat -n backend/src/auth/guards/roles.guard.ts
echo
echo "=== Checking if RolesGuard is exported from any index/barrel file ==="
rg -n 'RolesGuard' backend/src --glob '**/*index*' || true
echo
echo "=== Checking if RolesGuard appears in any .module.ts ==="
rg -n 'RolesGuard' backend/src --glob '**/*.module.ts' || true
echo
echo "=== Checking RolesGuard in auth.module.ts (full file) ==="
wc -l backend/src/auth/auth.module.tsRepository: OlufunbiIK/tip-tune Length of output: 282 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "=== Finding RolesGuard file ==="
find backend/src -name '*roles.guard*'
echo
echo "=== RolesGuard implementation ==="
cat -n backend/src/auth/guards/roles.guard.ts
echo
echo "=== Checking all .module.ts files for RolesGuard ==="
rg 'RolesGuard' backend/src --type ts -l
echo
echo "=== Full AuthModule file ==="
cat -n backend/src/auth/auth.module.tsRepository: OlufunbiIK/tip-tune Length of output: 3269 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "=== Checking app.module.ts ==="
find backend/src -name 'app.module.ts' -exec cat -n {} \;
echo
echo "=== Searching for RolesGuard in any import/provider context ==="
rg -B3 -A3 'RolesGuard' backend/src --type ts --glob '**/*.ts' | grep -E '(providers|imports|@Module)' || trueRepository: OlufunbiIK/tip-tune Length of output: 6788
To fix, add `@Module`({
imports: [TypeOrmModule.forFeature([User]), ...],
providers: [AuthService, WalletStrategy, JwtAuthGuard, RolesGuard],
exports: [AuthService, JwtAuthGuard, WalletStrategy, RolesGuard],
})
export class AuthModule {}Then import AuthModule into any module that uses 🤖 Prompt for AI Agents |
||
|
|
||
| canActivate(context: ExecutionContext): boolean { | ||
| async canActivate(context: ExecutionContext): Promise<boolean> { | ||
| const roles = this.reflector.get<UserRole[]>('roles', context.getHandler()); | ||
| if (!roles) { | ||
| return true; | ||
| } | ||
| const request = context.switchToHttp().getRequest(); | ||
| const user = request.user; | ||
| const principal = request.user as { userId?: string } | undefined; | ||
| if (!principal?.userId) return false; | ||
|
|
||
| const user = await this.userRepository.findOne({ | ||
| where: { id: principal.userId }, | ||
| select: ['id', 'role'], | ||
| }); | ||
| if (!user) return false; | ||
|
|
||
| return roles.includes(user.role); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid logging raw
userIdvalues on authorization failures.These warning paths persist stable user identifiers in auth logs. That is unnecessary for denial auditing and creates a privacy/compliance risk. Prefer a request/correlation ID, or redact/hash the principal before logging.
🛠️ Minimal fix
Also applies to: 58-60
🤖 Prompt for AI Agents