2020-02-01 16:11:48 +01:00
|
|
|
import { Injectable } from "@nestjs/common";
|
|
|
|
|
import { ConfigService } from "@nestjs/config";
|
|
|
|
|
import { PassportStrategy } from "@nestjs/passport";
|
|
|
|
|
import { Strategy, ExtractJwt } from "passport-jwt";
|
|
|
|
|
import { AuthService } from "./auth.service";
|
|
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
|
export class JwtStrategy extends PassportStrategy(Strategy) {
|
|
|
|
|
constructor(
|
2020-05-02 17:17:20 +02:00
|
|
|
private readonly authService: AuthService,
|
|
|
|
|
config: ConfigService
|
2020-02-01 16:11:48 +01:00
|
|
|
) {
|
|
|
|
|
super({
|
|
|
|
|
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
|
|
|
|
ignoreExpiration: false,
|
2020-05-02 17:17:20 +02:00
|
|
|
secretOrKey: config.get<string>("JWT_SECRET"),
|
2020-02-01 16:11:48 +01:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async validate(payload: any) {
|
|
|
|
|
return this.authService.findUser(payload.sub);
|
|
|
|
|
}
|
|
|
|
|
}
|