update auth

This commit is contained in:
2025-12-09 16:28:50 +03:30
parent f2094f87c5
commit 07f3006aef
4 changed files with 24 additions and 5 deletions
+11
View File
@@ -26,6 +26,10 @@ export class AuthGuard implements CanActivate {
try {
const secret = this.configService.getOrThrow<string>('JWT_SECRET');
const token = this.extractTokenFromHeader(request);
const slug = this.extractSlugFromHeader(request);
if (!slug) {
throw new UnauthorizedException('Slug is required');
}
if (!token) {
throw new UnauthorizedException();
}
@@ -38,6 +42,9 @@ export class AuthGuard implements CanActivate {
this.logger.error('Invalid token payload structure', payload);
throw new UnauthorizedException('Invalid token payload');
}
if (payload.slug !== slug) {
throw new UnauthorizedException('Invalid slug');
}
request['userId'] = payload.userId;
request['restId'] = payload.restId;
} catch {
@@ -57,4 +64,8 @@ export class AuthGuard implements CanActivate {
const [type, token] = request.headers.authorization?.split(' ') ?? [];
return type === 'Bearer' ? token : undefined;
}
private extractSlugFromHeader(request: Request): string | undefined {
const slug = request.headers['X-Slug'] as string;
return slug;
}
}