This commit is contained in:
2025-11-23 00:02:26 +03:30
parent cd4dc69aef
commit c8b0ee3c56
6 changed files with 373 additions and 345 deletions
+7 -1
View File
@@ -1,4 +1,4 @@
import { CanActivate, ExecutionContext, Injectable, UnauthorizedException, Inject } from '@nestjs/common';
import { CanActivate, ExecutionContext, Injectable, UnauthorizedException, Inject, Logger } from '@nestjs/common';
import { Request } from 'express';
import { JwtService } from '@nestjs/jwt';
import { ConfigService } from '@nestjs/config';
@@ -11,6 +11,8 @@ export interface AdminAuthRequest extends Request {
@Injectable()
export class AuthGuard implements CanActivate {
private readonly logger = new Logger(AuthGuard.name);
constructor(
@Inject(JwtService)
private readonly jwtService: JwtService,
@@ -32,6 +34,10 @@ export class AuthGuard implements CanActivate {
const payload = await this.jwtService.verifyAsync<ITokenPayload>(token, {
secret,
});
if (!payload.userId || !payload.restId) {
this.logger.error('Invalid token payload structure', payload);
throw new UnauthorizedException('Invalid token payload');
}
request['userId'] = payload.userId;
request['restId'] = payload.restId;
} catch {