From 74b3d246229f4b1dde16a3e9cf98b28a1a31f945 Mon Sep 17 00:00:00 2001
From: parsa aghaei
Date: Sat, 8 Aug 2026 18:11:17 +0330
Subject: [PATCH] fix(api/auth): allow public GET on ui-texts &
scientific-terms, fix refresh attempt loop, remove duplicate error toasts and
prevent unwanted modal popups
---
backend/src/settings/settings.controller.ts | 26 +++++++++++++++----
.../src/videos/dto/get-videos-query.dto.ts | 21 +++++++++++++++
backend/src/videos/videos.controller.ts | 5 ++--
frontend/admin-panel/src/pages/Login.tsx | 2 +-
frontend/admin-panel/src/services/api.ts | 3 ++-
frontend/application/lib/services/api.ts | 1 -
6 files changed, 48 insertions(+), 10 deletions(-)
create mode 100644 backend/src/videos/dto/get-videos-query.dto.ts
diff --git a/backend/src/settings/settings.controller.ts b/backend/src/settings/settings.controller.ts
index 4af43cdc..96f5128c 100644
--- a/backend/src/settings/settings.controller.ts
+++ b/backend/src/settings/settings.controller.ts
@@ -21,8 +21,6 @@ import {
} from '@nestjs/swagger';
@ApiTags('Settings - تنظیمات متون پویا، تنظیمات سئو، مالی و سیستم')
-@UseGuards(JwtAuthGuard, RolesGuard)
-@Roles('Admin')
@Controller('settings')
export class SettingsController {
constructor(private readonly settingsService: SettingsService) {}
@@ -37,7 +35,8 @@ export class SettingsController {
return this.settingsService.getUiTexts();
}
- @UseGuards(JwtAuthGuard)
+ @UseGuards(JwtAuthGuard, RolesGuard)
+ @Roles('Admin')
@ApiBearerAuth()
@Patch('ui-texts/:key')
@ApiOperation({ summary: 'ویرایش متن یک کلید در رابط کاربری' })
@@ -51,7 +50,8 @@ export class SettingsController {
return this.settingsService.getScientificTerms();
}
- @UseGuards(JwtAuthGuard)
+ @UseGuards(JwtAuthGuard, RolesGuard)
+ @Roles('Admin')
@ApiBearerAuth()
@Put('scientific-terms/:key')
@ApiOperation({ summary: 'ثبت یا ویرایش یک اصطلاح علمی' })
@@ -62,7 +62,8 @@ export class SettingsController {
return this.settingsService.upsertScientificTerm(key, data);
}
- @UseGuards(JwtAuthGuard)
+ @UseGuards(JwtAuthGuard, RolesGuard)
+ @Roles('Admin')
@ApiBearerAuth()
@Delete('scientific-terms/:key')
@ApiOperation({ summary: 'حذف یک اصطلاح علمی' })
@@ -77,6 +78,9 @@ export class SettingsController {
return this.settingsService.getCategorySetting('seo');
}
+ @UseGuards(JwtAuthGuard, RolesGuard)
+ @Roles('Admin')
+ @ApiBearerAuth()
@Patch('seo')
@ApiOperation({ summary: 'بهروزرسانی تنظیمات سئو' })
updateSeoSettings(@Body() body: Prisma.InputJsonValue) {
@@ -84,12 +88,18 @@ export class SettingsController {
}
// Financial Settings
+ @UseGuards(JwtAuthGuard, RolesGuard)
+ @Roles('Admin')
+ @ApiBearerAuth()
@Get('financial')
@ApiOperation({ summary: 'دریافت تنظیمات مالی' })
getFinancialSettings() {
return this.settingsService.getCategorySetting('financial');
}
+ @UseGuards(JwtAuthGuard, RolesGuard)
+ @Roles('Admin')
+ @ApiBearerAuth()
@Patch('financial')
@ApiOperation({ summary: 'بهروزرسانی تنظیمات مالی' })
updateFinancialSettings(@Body() body: Prisma.InputJsonValue) {
@@ -97,12 +107,18 @@ export class SettingsController {
}
// System Settings
+ @UseGuards(JwtAuthGuard, RolesGuard)
+ @Roles('Admin')
+ @ApiBearerAuth()
@Get('system')
@ApiOperation({ summary: 'دریافت تنظیمات سیستم' })
getSystemSettings() {
return this.settingsService.getCategorySetting('system');
}
+ @UseGuards(JwtAuthGuard, RolesGuard)
+ @Roles('Admin')
+ @ApiBearerAuth()
@Patch('system')
@ApiOperation({ summary: 'بهروزرسانی تنظیمات سیستم' })
updateSystemSettings(@Body() body: Prisma.InputJsonValue) {
diff --git a/backend/src/videos/dto/get-videos-query.dto.ts b/backend/src/videos/dto/get-videos-query.dto.ts
new file mode 100644
index 00000000..90ab6eef
--- /dev/null
+++ b/backend/src/videos/dto/get-videos-query.dto.ts
@@ -0,0 +1,21 @@
+import { ApiPropertyOptional } from '@nestjs/swagger';
+import { IsOptional, IsString, IsBoolean } from 'class-validator';
+import { Transform } from 'class-transformer';
+import { PaginationDto } from '../../common/dto/pagination.dto';
+
+export class GetVideosQueryDto extends PaginationDto {
+ @ApiPropertyOptional({ description: 'فیلتر بر اساس ویدئوهای ویژه (true/false)' })
+ @IsOptional()
+ @Transform(({ value }) => {
+ if (value === 'true' || value === true) return true;
+ if (value === 'false' || value === false) return false;
+ return value;
+ })
+ @IsBoolean()
+ featured?: boolean;
+
+ @ApiPropertyOptional({ description: 'جستجو در عنوان، پزشک یا توضیحات' })
+ @IsOptional()
+ @IsString()
+ override search?: string;
+}
diff --git a/backend/src/videos/videos.controller.ts b/backend/src/videos/videos.controller.ts
index eaaeb36f..bb43d5fc 100644
--- a/backend/src/videos/videos.controller.ts
+++ b/backend/src/videos/videos.controller.ts
@@ -9,8 +9,9 @@ import {
Query,
UseGuards,
} from '@nestjs/common';
-import { VideosService, VideoQuery } from './videos.service';
+import { VideosService } from './videos.service';
import { CreateVideoDto } from './dto/create-video.dto';
+import { GetVideosQueryDto } from './dto/get-videos-query.dto';
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
import {
ApiTags,
@@ -30,7 +31,7 @@ export class VideosController {
@ApiQuery({ name: 'limit', required: false })
@ApiQuery({ name: 'search', required: false })
@ApiQuery({ name: 'featured', required: false })
- findAll(@Query() query: VideoQuery) {
+ findAll(@Query() query: GetVideosQueryDto) {
return this.videosService.findAll(query);
}
diff --git a/frontend/admin-panel/src/pages/Login.tsx b/frontend/admin-panel/src/pages/Login.tsx
index 25aa4fd2..5b9ca946 100644
--- a/frontend/admin-panel/src/pages/Login.tsx
+++ b/frontend/admin-panel/src/pages/Login.tsx
@@ -33,7 +33,7 @@ export default function Login() {
toast.error('اطلاعات ورود نامعتبر است');
}
} catch {
- toast.error('ایمیل یا رمز عبور اشتباه است');
+ // Toast notification is handled by api.ts interceptor
} finally {
setIsLoading(false);
}
diff --git a/frontend/admin-panel/src/services/api.ts b/frontend/admin-panel/src/services/api.ts
index 5112fd87..188d928b 100644
--- a/frontend/admin-panel/src/services/api.ts
+++ b/frontend/admin-panel/src/services/api.ts
@@ -62,7 +62,8 @@ api.interceptors.response.use(
const farsiMessage = responseData?.message || 'خطایی در ارتباط با سرور رخ داده است.';
if (status === 401 && originalRequest && !originalRequest._retry) {
- if (originalRequest.url?.includes('/auth/refresh') || originalRequest.url?.includes('/auth/admin-login') || originalRequest.url?.includes('/auth/verify-otp')) {
+ const currentToken = useAdminAuthStore.getState().accessToken;
+ if (!currentToken || originalRequest.url?.includes('/auth/refresh') || originalRequest.url?.includes('/auth/admin-login') || originalRequest.url?.includes('/auth/verify-otp')) {
useAdminAuthStore.getState().clearAuth();
if (window.location.pathname !== '/login') {
toast.error('نشست کاری شما منقضی شده است. لطفاً مجدداً وارد شوید.');
diff --git a/frontend/application/lib/services/api.ts b/frontend/application/lib/services/api.ts
index 9ff7c40d..45ed1638 100644
--- a/frontend/application/lib/services/api.ts
+++ b/frontend/application/lib/services/api.ts
@@ -60,7 +60,6 @@ api.interceptors.response.use(
}
try {
useUserStore.getState().logout();
- useUserStore.getState().setAuthModalOpen(true);
} catch {
// Ignore if store not ready
}