2023-02-16 12:09:48 +08:00
|
|
|
import { Strategy, ExtractJwt } from 'passport-jwt'
|
|
|
|
import { PassportStrategy } from '@nestjs/passport'
|
2023-02-21 11:13:21 +08:00
|
|
|
import { Injectable, Inject } from '@nestjs/common'
|
2023-02-17 11:49:16 +08:00
|
|
|
import { TokenPayload } from '../dto/token.dto'
|
2023-02-21 11:13:21 +08:00
|
|
|
import { securityConfig, SecurityConfig } from 'src/common/configs'
|
2023-02-16 12:09:48 +08:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class JwtStrategy extends PassportStrategy(Strategy) {
|
2023-02-21 11:13:21 +08:00
|
|
|
constructor(
|
|
|
|
@Inject(securityConfig.KEY)
|
|
|
|
readonly secureConfig: SecurityConfig,
|
|
|
|
) {
|
2023-02-16 12:09:48 +08:00
|
|
|
super({
|
|
|
|
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
2023-02-21 11:13:21 +08:00
|
|
|
secretOrKey: secureConfig.jwt_access_secret,
|
2023-02-16 12:09:48 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-02-17 11:49:16 +08:00
|
|
|
async validate(payload: TokenPayload) {
|
|
|
|
return payload
|
2023-02-16 12:09:48 +08:00
|
|
|
}
|
|
|
|
}
|