mirror of
https://github.com/Kevsl/crypto-exchange-api.git
synced 2025-07-08 21:50:13 +02:00
29 lines
776 B
TypeScript
29 lines
776 B
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { ConfigService } from '@nestjs/config';
|
|
import { PassportStrategy } from '@nestjs/passport';
|
|
import { ExtractJwt, Strategy } from 'passport-jwt';
|
|
import { PrismaService } from '../../prisma/prisma.service';
|
|
|
|
@Injectable()
|
|
export class JwtStrategy extends PassportStrategy(Strategy, 'jwt') {
|
|
constructor(
|
|
config: ConfigService,
|
|
private prisma: PrismaService,
|
|
) {
|
|
super({
|
|
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
|
secretOrKey: config.get('JWT_SECRET'),
|
|
});
|
|
}
|
|
|
|
async validate(payload: { sub: string; email: string }) {
|
|
const user = await this.prisma.user.findUnique({
|
|
where: {
|
|
id: payload.sub,
|
|
},
|
|
});
|
|
delete user.hash;
|
|
return user;
|
|
}
|
|
}
|