mirror of
https://github.com/apricote/Listory.git
synced 2026-01-13 21:21:02 +00:00
23 lines
679 B
TypeScript
23 lines
679 B
TypeScript
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(
|
|
private readonly authService: AuthService,
|
|
config: ConfigService
|
|
) {
|
|
super({
|
|
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
|
ignoreExpiration: false,
|
|
secretOrKey: config.get<string>("JWT_SECRET"),
|
|
});
|
|
}
|
|
|
|
async validate(payload: any) {
|
|
return this.authService.findUser(payload.sub);
|
|
}
|
|
}
|