mirror of
https://github.com/swissmakers/swiss-datashare.git
synced 2026-04-11 10:27:01 +02:00
25 lines
748 B
TypeScript
25 lines
748 B
TypeScript
import { Injectable } from "@nestjs/common";
|
|
import { ConfigService } from "@nestjs/config";
|
|
import { PassportStrategy } from "@nestjs/passport";
|
|
import { User } from "@prisma/client";
|
|
import { ExtractJwt, Strategy } from "passport-jwt";
|
|
import { PrismaService } from "src/prisma/prisma.service";
|
|
|
|
@Injectable()
|
|
export class JwtStrategy extends PassportStrategy(Strategy) {
|
|
constructor(config: ConfigService, private prisma: PrismaService) {
|
|
super({
|
|
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
|
secretOrKey: config.get("JWT_SECRET"),
|
|
});
|
|
}
|
|
|
|
async validate(payload: { sub: string }) {
|
|
const user: User = await this.prisma.user.findUnique({
|
|
where: { id: payload.sub },
|
|
});
|
|
|
|
return user;
|
|
}
|
|
}
|