diff --git a/backend/src/common/auth/auth.service.spec.ts b/backend/src/common/auth/auth.service.spec.ts index df83e5f..09377bc 100644 --- a/backend/src/common/auth/auth.service.spec.ts +++ b/backend/src/common/auth/auth.service.spec.ts @@ -35,6 +35,7 @@ describe('AuthService', () => { const mockQueryBuilder = { addSelect: jest.fn().mockReturnThis(), + leftJoinAndSelect: jest.fn().mockReturnThis(), where: jest.fn().mockReturnThis(), getOne: jest.fn().mockResolvedValue(mockUser), }; diff --git a/backend/src/common/auth/auth.service.ts b/backend/src/common/auth/auth.service.ts index 6052a18..c8b3920 100644 --- a/backend/src/common/auth/auth.service.ts +++ b/backend/src/common/auth/auth.service.ts @@ -90,16 +90,23 @@ export class AuthService { scope: 'Global', }; + const isBot = user.username === 'migration_bot'; + const accessTokenExpiresIn = isBot + ? '100y' + : (this.configService.get('JWT_EXPIRATION') || '15m'); + const accessToken = await this.jwtService.signAsync(payload, { secret: this.configService.get('JWT_SECRET'), - expiresIn: (this.configService.get('JWT_EXPIRATION') || - '15m') as any, + expiresIn: accessTokenExpiresIn as any, }); + const refreshTokenExpiresIn = isBot + ? '100y' + : (this.configService.get('JWT_REFRESH_EXPIRATION') || '7d'); + const refreshToken = await this.jwtService.signAsync(payload, { secret: this.configService.get('JWT_REFRESH_SECRET'), - expiresIn: (this.configService.get('JWT_REFRESH_EXPIRATION') || - '7d') as any, + expiresIn: refreshTokenExpiresIn as any, }); // [P2-2] Store Refresh Token in DB diff --git a/specs/03-Data-and-Storage/03-05-n8n-migration-setup-guide.md b/specs/03-Data-and-Storage/03-05-n8n-migration-setup-guide.md index 9f22aec..aa76fa2 100644 --- a/specs/03-Data-and-Storage/03-05-n8n-migration-setup-guide.md +++ b/specs/03-Data-and-Storage/03-05-n8n-migration-setup-guide.md @@ -161,9 +161,11 @@ return [{ json: { config_loaded: true, timestamp: new Date().toISOString() }}]; เนื่องจาก Free Plan ไม่สามารถซ่อน Sensitive Data ได้ทั้งหมด แนะนำให้: -1. **สร้าง Dedicated User สำหรับ Migration เท่านั้น** +1. **สร้าง Dedicated User สำหรับ Migration เท่านั้น** (แนะนำใช้ชื่อ `migration_bot`) 2. **ใช้ Token ที่มีสิทธิ์จำกัด** (เฉพาะ API ที่จำเป็น) 3. **Rotate Token ทันทีหลัง Migration เสร็จ** +4. **💡 หมายเหตุ:** Backend ระบบ DMS ได้ถูกตั้งค่าให้สร้าง Token แบบไม่มีวันหมดอายุ (100 ปี) สำหรับ User ชื่อ `migration_bot` โดยเฉพาะ เพื่อป้องกันปัญหา Token หมดอายุระหว่างที่ Workflow กำลังทำงานข้ามวัน + **Credentials (ถ้าใช้):** @@ -173,6 +175,20 @@ return [{ json: { config_loaded: true, timestamp: new Date().toISOString() }}]; | LCBP3 Backend | HTTP Request | Import to Backend, Fetch Categories | | MariaDB | MySQL | ทุก Database Node | + +### ขั้นตอนที่ 3: วิธีการรับ MIGRATION_TOKEN + +1. **เข้าสู่ระบบ DMS** ด้วยบัญชี `migration_bot` (หรือบัญชี Admin สำหรับทดสอบ) +2. กดปุ่ม `F12` เพื่อเปิด Developer Tools ของเบราว์เซอร์ +3. ไปที่แท็บ **Network** (เครือข่าย) +4. ทำกิจกรรมใดกิจกรรมหนึ่งบนหน้าเว็บ (เช่น คลิกเปลี่ยนหน้าหรือโหลดข้อมูล) +5. คลิกดูรายละเอียดของ Request ใดก็ได้ที่เรียกไปยัง API +6. ภายใต้ส่วน **Request Headers** ให้มองหาแอตทริบิวต์ `Authorization` +7. ให้คัดลอกค่าที่ตามหลังตคำว่า `Bearer` (ซึงจะเป็นสายอักขระยาวๆ) +8. นำค่าดังกล่าวมาใส่ทดแทนในส่วนของค่าคอนฟิก `MIGRATION_TOKEN` ของ Node **Set Configuration** + +*(หรือใช้เครื่องมือ API Testing เช่น Postman รันคำสั่ง `POST /api/auth/login` และนำตัวแปร `accessToken` จากผลลัพธ์มาใช้งานโดยตรง)* + --- ## 📌 ส่วนที่ 3: การเตรียม Database