fix(api/auth): allow public GET on ui-texts & scientific-terms, fix refresh attempt loop, remove duplicate error toasts and prevent unwanted modal popups
Deploy Canina / deploy (push) Failing after 28s
Deploy Canina / deploy (push) Failing after 28s
This commit is contained in:
1 parent
adbfa60343
commit
74b3d24622
6 files changed
+48
-10
No files matched your search
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ export default function Login() {
|
||||
toast.error('اطلاعات ورود نامعتبر است');
|
||||
}
|
||||
} catch {
|
||||
toast.error('ایمیل یا رمز عبور اشتباه است');
|
||||
// Toast notification is handled by api.ts interceptor
|
||||
} finally {
|
||||
setIsLoading(false);
|
||||
}
|
||||
|
||||
@@ -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('نشست کاری شما منقضی شده است. لطفاً مجدداً وارد شوید.');
|
||||
|
||||
@@ -60,7 +60,6 @@ api.interceptors.response.use(
|
||||
}
|
||||
try {
|
||||
useUserStore.getState().logout();
|
||||
useUserStore.getState().setAuthModalOpen(true);
|
||||
} catch {
|
||||
// Ignore if store not ready
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user