feat(auth): add detailed logging in JwtAuthGuard and JwtStrategy for better debugging
feat(products): enhance logging in create method to track requests and user details
This commit is contained in:
@@ -10,11 +10,23 @@ export class JwtAuthGuard extends AuthGuard('jwt') {
|
||||
}
|
||||
|
||||
canActivate(context: ExecutionContext) {
|
||||
const request = context.switchToHttp().getRequest();
|
||||
const authHeader = request.headers.authorization;
|
||||
const path = request.path;
|
||||
const method = request.method;
|
||||
console.log(`[JwtAuthGuard.canActivate] ${method} ${path}`);
|
||||
console.log(`[JwtAuthGuard.canActivate] Authorization header:`, authHeader ? 'YES' : 'NO');
|
||||
|
||||
const isPublic = this.reflector.getAllAndOverride<boolean>(IS_PUBLIC_KEY, [
|
||||
context.getHandler(),
|
||||
context.getClass(),
|
||||
]);
|
||||
console.log(`[JwtAuthGuard.canActivate] isPublic:`, isPublic);
|
||||
|
||||
if (isPublic) return true;
|
||||
return super.canActivate(context);
|
||||
|
||||
const result = super.canActivate(context);
|
||||
console.log(`[JwtAuthGuard.canActivate] super.canActivate result:`, result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,9 @@ export class JwtStrategy extends PassportStrategy(Strategy) {
|
||||
}
|
||||
|
||||
async validate(payload: { sub: number; username: string; role: string; isPremium: boolean }) {
|
||||
return { userId: payload.sub, username: payload.username, role: payload.role ?? 'user', isPremium: payload.isPremium ?? false };
|
||||
console.log('[JwtStrategy.validate] Payload received:', payload);
|
||||
const result = { userId: payload.sub, username: payload.username, role: payload.role ?? 'user', isPremium: payload.isPremium ?? false };
|
||||
console.log('[JwtStrategy.validate] Returning user:', result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user