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