Use owner enums for error and T-Bank protocol values with ESLint regression checks. Preserve open wire fallbacks and keep protocol imports independent of DI and Prisma. Verified npm ci, verify, 226 unit tests, 262 isolated e2e tests and unchanged OpenAPI.
28 lines
938 B
TypeScript
28 lines
938 B
TypeScript
import { Injectable, UnauthorizedException } from '@nestjs/common';
|
|
import { ConfigService } from '@nestjs/config';
|
|
import { PassportStrategy } from '@nestjs/passport';
|
|
import { ExtractJwt, Strategy } from 'passport-jwt';
|
|
|
|
import { HttpErrorCode } from '../../../common/error-code';
|
|
import { Environment } from '../../../config/env.validation';
|
|
import { AccessPayload } from '../application/auth.types';
|
|
|
|
@Injectable()
|
|
export class JwtStrategy extends PassportStrategy(Strategy) {
|
|
constructor(config: ConfigService<Environment, true>) {
|
|
super({
|
|
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
|
ignoreExpiration: false,
|
|
secretOrKey: config.getOrThrow('JWT_SECRET'),
|
|
algorithms: ['HS256'],
|
|
});
|
|
}
|
|
|
|
validate(payload: AccessPayload): AccessPayload {
|
|
if (payload.type !== 'access') {
|
|
throw new UnauthorizedException({ code: HttpErrorCode.Unauthorized });
|
|
}
|
|
return payload;
|
|
}
|
|
}
|