fix jwt guard user repository resolution
This commit is contained in:
@@ -5,8 +5,7 @@ import {
|
||||
UnauthorizedException,
|
||||
} from '@nestjs/common';
|
||||
import { JwtService } from '@nestjs/jwt';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { DataSource } from 'typeorm';
|
||||
import { UserEntity } from '../../../entities/user.entity';
|
||||
import { AuthUser, JwtPayload } from '../auth.types';
|
||||
|
||||
@@ -21,8 +20,7 @@ type RequestWithUser = Request & {
|
||||
export class JwtAuthGuard implements CanActivate {
|
||||
constructor(
|
||||
private readonly jwt: JwtService,
|
||||
@InjectRepository(UserEntity)
|
||||
private readonly users: Repository<UserEntity>,
|
||||
private readonly dataSource: DataSource,
|
||||
) {}
|
||||
|
||||
async canActivate(context: ExecutionContext): Promise<boolean> {
|
||||
@@ -35,7 +33,7 @@ export class JwtAuthGuard implements CanActivate {
|
||||
|
||||
try {
|
||||
const payload = await this.jwt.verifyAsync<JwtPayload>(token);
|
||||
const user = await this.users.findOne({
|
||||
const user = await this.dataSource.getRepository(UserEntity).findOne({
|
||||
where: { id: payload.sub, isActive: true },
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user