From b8b55951e80ec80fbe4cadef0cae04fa73fa6b0a Mon Sep 17 00:00:00 2001 From: DmitriyA Date: Wed, 26 Mar 2025 07:55:39 -0400 Subject: [PATCH 1/2] CORS settings --- src/auth/auth.service.ts | 6 +----- src/main.ts | 5 ++++- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index 695c51c..206b5f9 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -11,21 +11,17 @@ export class AuthService { ) { } async validateUser(login: string, password: string): Promise { - console.log(`Проверка пользователя: ${login}, пароль: ${password}`); // Ищем пользователя по login const user = await this.usersRepository.findOne({ where: { login } }); - console.log(`Найденный пользователь:`, user); - // Проверяем, что нашли пользователя и пароль совпадает if (user && user.password === password) { - console.log(`Авторизация успешна`); + const { password, ...result } = user; return result; } - console.log(`Ошибка: неверный логин или пароль`); return null; } } diff --git a/src/main.ts b/src/main.ts index ac585d9..8933d99 100644 --- a/src/main.ts +++ b/src/main.ts @@ -5,9 +5,12 @@ import { AppModule } from './app.module'; async function bootstrap() { const app = await NestFactory.create(AppModule); + //настройка CORS + app.enableCors({ origin: '*', - methods: 'GET,HEAD,PUT,PATCH,POST,DELETE', + //methods: 'GET,HEAD,PUT,PATCH,POST,DELETE', + methods: '*', allowedHeaders: 'Content-Type, Authorization', }); await app.listen(process.env.PORT ?? 3000); -- 2.40.1 From c02a6fdbe1668f98446b36a97d8b6bc3400e8fa0 Mon Sep 17 00:00:00 2001 From: DmitriyA Date: Wed, 26 Mar 2025 08:38:02 -0400 Subject: [PATCH 2/2] add OPTIONS --- src/main.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main.ts b/src/main.ts index 8933d99..88fd9d2 100644 --- a/src/main.ts +++ b/src/main.ts @@ -9,8 +9,7 @@ async function bootstrap() { app.enableCors({ origin: '*', - //methods: 'GET,HEAD,PUT,PATCH,POST,DELETE', - methods: '*', + methods: 'GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS', allowedHeaders: 'Content-Type, Authorization', }); await app.listen(process.env.PORT ?? 3000); -- 2.40.1