fix(admin-service): 注册 JwtStrategy 解决 "Unknown authentication strategy" 错误

admin-service 使用了 @genex/common 的 JwtAuthGuard 保护管理端接口,
但缺少对应的 Passport JWT Strategy 注册。新增轻量级 JwtStrategy,
仅验证 token 签名和提取 payload,不依赖 UserRepository。

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
hailin 2026-03-03 08:16:38 -08:00
parent 6f87be4454
commit fcf49b5257
2 changed files with 20 additions and 0 deletions

View File

@ -17,6 +17,7 @@ import { PACKAGE_PARSER } from './domain/ports/package-parser.interface';
// Infrastructure
import { AppVersionRepository } from './infrastructure/persistence/app-version.repository';
import { PackageParserService } from './infrastructure/parsers/package-parser.service';
import { JwtStrategy } from './infrastructure/strategies/jwt.strategy';
// Interface - Controllers
import { AppVersionController } from './interface/http/controllers/app-version.controller';
@ -57,6 +58,7 @@ import { HealthController } from './interface/http/controllers/health.controller
AppVersionService,
FileStorageService,
{ provide: PACKAGE_PARSER, useClass: PackageParserService },
JwtStrategy,
],
})
export class AdminModule {}

View File

@ -0,0 +1,18 @@
import { Injectable } from '@nestjs/common';
import { PassportStrategy } from '@nestjs/passport';
import { ExtractJwt, Strategy } from 'passport-jwt';
@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') {
constructor() {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
ignoreExpiration: false,
secretOrKey: process.env.JWT_ACCESS_SECRET || 'dev-access-secret',
});
}
async validate(payload: { sub: string; role: string; kycLevel: number; type: string }) {
return { sub: payload.sub, role: payload.role, kycLevel: payload.kycLevel };
}
}