add logger
Deploy / deploy (push) Failing after 24s

This commit is contained in:
Rayyan
2026-08-03 23:46:19 +07:00
parent e0bf3882be
commit 6ffff9ef7b
8 changed files with 210 additions and 10 deletions
+29
View File
@@ -0,0 +1,29 @@
import { Injectable, Logger } from '@nestjs/common';
import { PassportStrategy } from '@nestjs/passport';
import { Strategy as JwtStrategyBase, ExtractJwt } from 'passport-jwt';
import { ConfigService } from '@nestjs/config';
function cookieExtractor(req: any): string | null {
if (!req) return null;
if (req.cookies && req.cookies.raylab_jwt) return req.cookies.raylab_jwt as string;
return null;
}
@Injectable()
export class JwtStrategy extends PassportStrategy(JwtStrategyBase, 'jwt') {
private readonly logger = new Logger('JwtStrategy');
constructor(private config: ConfigService) {
super({
jwtFromRequest: ExtractJwt.fromExtractors([cookieExtractor, ExtractJwt.fromAuthHeaderAsBearerToken()]),
secretOrKey: config.get<string>('RAYLAB_JWT_SECRET') || process.env.RAYLAB_JWT_SECRET || 'raylab-secret',
algorithms: ['HS256'],
});
this.logger.debug('JwtStrategy initialized');
}
async validate(payload: any) {
this.logger.debug(`JwtStrategy.validate payload=${JSON.stringify(payload)}`);
return payload; // attached to req.user
}
}