Files
scheduler-back/src/middleware/auth/jwt.strategy.ts
Hyang-Dan 5c79aa18f4
Some checks failed
Test CI / build (push) Failing after 28s
issue #39
- 로그인 이후 access/refresh token 생성 및 반환 로직 구현
2025-11-30 18:19:39 +09:00

27 lines
951 B
TypeScript

import { Injectable, UnauthorizedException } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { JwtService } from '@nestjs/jwt';
import { PassportStrategy } from '@nestjs/passport';
import { ExtractJwt, Strategy } from 'passport-jwt';
import { AccountRepo } from 'src/modules/account/account.repo';
@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
constructor(
private readonly accountRepo: AccountRepo
, private readonly configService: ConfigService
, private readonly jwtService: JwtService
) {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
ignoreExpiration: false,
secretOrKey: configService.get<string>('JWT_SECRET')!
});
}
async validate(payload: any) {
const account = await this.accountRepo.findById(payload.id);
if (!account || account.length < 1) throw new UnauthorizedException();
return account[0];
}
}