Some checks failed
Test CI / build (push) Failing after 28s
- 로그인 이후 access/refresh token 생성 및 반환 로직 구현
27 lines
951 B
TypeScript
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];
|
|
}
|
|
} |