hailin
0420b0acab
fix(trading,auth): add parent .env path for shared JWT_SECRET
...
Both services need to read JWT_SECRET from the shared .env file
in the parent directory (backend/services/.env).
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-15 06:57:57 -08:00
hailin
c852f24a72
fix(auth-service): add 'auth/' prefix to controller routes for Kong compatibility
...
Kong routes /api/v2/auth/* to auth-service without stripping the path,
so controllers need 'auth/' prefix to match frontend requests:
- SmsController: 'sms' -> 'auth/sms'
- PasswordController: 'password' -> 'auth/password'
- UserController: 'user' -> 'auth/user'
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 08:53:48 -08:00
hailin
9037c2da97
feat(auth): implement transactional idempotent CDC consumer for 1.0->2.0 sync
...
Implements 100% exactly-once semantics for CDC events from 1.0 identity-service
(user_accounts table) to auth-service.
Key changes:
- Add ProcessedCdcEvent model with (sourceTopic, offset) unique constraint
- Implement processWithIdempotency() using Serializable transaction isolation
- All database operations now use the transaction client
- Outbox event creation is also within the same transaction
This ensures that:
1. Each CDC event is processed exactly once
2. Idempotency record and business logic are in the same transaction
3. Outbox event publishing is atomic with data sync
4. Any failure causes complete rollback
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 19:29:42 -08:00
hailin
30b04c6376
feat(sync): 完善 CDC 数据同步 - 添加推荐关系、认种记录和昵称字段
...
- auth-service:
- SyncedLegacyUser 表添加 nickname 字段
- LegacyUserMigratedEvent 添加 nickname 参数
- CDC consumer 同步 nickname 字段
- SyncedLegacyUserData 接口添加 nickname
- contribution-service:
- 新增 ReferralSyncedEvent 事件类
- 新增 AdoptionSyncedEvent 事件类
- admin.controller 添加 publish-all APIs:
- POST /admin/referrals/publish-all
- POST /admin/adoptions/publish-all
- mining-admin-service:
- SyncedUser 表添加 nickname 字段
- 新增 SyncedReferral 表 (推荐关系)
- 新增 SyncedAdoption 表 (认种记录)
- handleReferralSynced 处理器
- handleAdoptionSynced 处理器
- handleLegacyUserMigrated 处理 nickname
- deploy-mining.sh:
- full_reset 更新为 14 步
- Step 13: 发布推荐关系
- Step 14: 发布认种记录
解决 mining-admin-web 缺少昵称、推荐人、认种数据的问题
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 02:48:15 -08:00
hailin
cbdb449533
fix(auth): 修复 LegacyUserCdcConsumer 的 OutboxService 依赖注入
...
- 在 ApplicationModule 中导出 OutboxService
- 在 InfrastructureModule 中使用 forwardRef 导入 ApplicationModule
- 解决循环依赖问题
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 02:00:21 -08:00
hailin
4cbdf0b503
fix(auth): 修复 CDC consumer 类型错误
...
使用 ?? 运算符正确处理可选字段:
- update 使用 undefined 保持字段不变
- create 使用 null 明确设置为空值
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 01:45:10 -08:00
hailin
489966fae9
feat(auth): 新 1.0 用户自动发布事件到 mining-admin-service
...
- auth-service CDC consumer 在同步新用户时自动发布 LegacyUserMigratedEvent
- 只有 op='c' (create) 的新用户才发布事件,snapshot 由 publish-all API 处理
- deploy-mining.sh full-reset 更新步骤编号为 10 步
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 01:25:01 -08:00
hailin
582beb4f81
feat(cdc): 添加 legacy 用户批量同步功能
...
auth-service:
- 添加 AdminController 和 AdminSyncService
- POST /admin/legacy-users/publish-all: 为所有 legacy 用户发布事件
- GET /admin/users/sync: 获取所有用户数据供同步
mining-admin-service:
- 添加 user.legacy.migrated 事件处理器
- 添加 sync-users 和 sync-contribution-accounts API
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 20:17:46 -08:00
hailin
49b1571bba
fix(cdc): 修复 auth-service 与 mining-admin-service 的 CDC 事件同步
...
- auth-service: 将 outbox topic 从 auth.events 改为 mining-admin.auth.users
- mining-admin-service: 添加 user.registered 和 user.kyc_verified 事件处理器
- 确保 auth-service 发布的事件能被 mining-admin-service 正确接收和处理
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 19:51:01 -08:00
hailin
7a68668aa9
feat(auth-service): 增强登录错误提示和指数退避锁定机制
...
- 区分用户不存在和密码错误的提示信息
- 登录失败最多允许6次尝试
- 每次密码错误显示剩余尝试次数
- 超过次数后实现指数退避锁定(1,2,4,8...分钟,最长24小时)
- 锁定时显示剩余等待时间
- 优化mining-app底部导航栏图标间距
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 18:33:23 -08:00
hailin
849fa77df0
fix(auth-service): 允许synced_legacy_users的phone和password_hash为空
...
- 修改schema让phone和passwordHash字段可为空
- 添加migration: 20260111083500_allow_nullable_phone_password
- CDC consumer使用null替代空字符串
- 支持同步没有手机号/密码的系统账户
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 08:37:02 -08:00
hailin
6caae7c860
fix(auth-service): 跳过无手机号/密码的系统账户CDC同步
...
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 08:33:39 -08:00
hailin
4bb995f2c2
feat(auth-service,mining-app): 实现完整认证流程和CDC用户同步
...
auth-service:
- 添加DTO验证装饰器(IsString, IsNotEmpty, Matches, MinLength)
- 添加短信验证码登录(loginBySms)方法
- 修复CDC Consumer字段映射匹配1.0 user_accounts表
- 更新CDC topic为cdc.identity.public.user_accounts
mining-app (Flutter):
- 新增auth_remote_datasource实现真实API调用
- 新增登录页面(密码/短信切换)和注册页面
- 替换splash_page中的mock登录为真实状态检查
- 添加token自动注入拦截器到ApiClient
- 配置生产环境API指向Kong网关
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 05:29:48 -08:00
hailin
7f72c1e1ec
fix(2.0-services): 修复InfrastructureModule导出PrismaService问题
...
NestJS不允许模块导出未在providers中声明的服务。
将exports中的PrismaService改为PrismaModule(因为PrismaModule已导出PrismaService)。
修复服务:
- mining-admin-service
- auth-service
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-11 00:00:50 -08:00
hailin
ee5f841034
fix(outbox): 实现指数退避重试策略,最大延迟3小时
...
修复Outbox事件发布的重试机制:
1. 更新Prisma Schema (mining-service, trading-service):
- 添加OutboxStatus枚举 (PENDING, PUBLISHED, FAILED)
- 添加topic、key、status、retryCount、maxRetries、lastError等字段
- 添加publishedAt、nextRetryAt时间戳
- 优化索引 (status, nextRetryAt, createdAt)
2. 更新OutboxRepository (mining-service, trading-service):
- findPendingEvents(): 查询待处理且到达重试时间的事件
- markAsPublished(): 标记事件已发布
- markAsFailed(): 实现指数退避算法 (30s基础, 最大3小时)
- deletePublished(): 清理已发布的旧事件
3. 更新OutboxScheduler (auth/mining/trading-service):
- 使用指数退避: 30s, 60s, 120s, 240s, ... 最大10800s (3小时)
- 记录重试次数和错误信息
- 达到最大重试次数后标记为FAILED
指数退避公式: delay = min(30s * 2^(retryCount-1), 3h)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 21:08:57 -08:00
hailin
28ad8c2e2f
feat(2.0-services): 为auth/mining/trading服务添加Outbox事件发布机制
...
- auth-service:
- 添加Kafka生产者模块和服务
- 添加Redis服务用于分布式锁
- 添加OutboxScheduler定时发布Outbox事件到Kafka
- 更新InfrastructureModule为全局模块
- mining-service:
- 添加Kafka生产者服务
- 添加OutboxRepository用于管理Outbox事件
- 添加OutboxScheduler定时发布事件
- trading-service:
- 添加Kafka生产者服务
- 添加OutboxRepository用于管理Outbox事件
- 添加OutboxScheduler定时发布事件
所有服务的Outbox调度器:
- 每30秒发布待处理的事件到Kafka
- 每天凌晨3点清理7天前已处理的事件
- 使用Redis分布式锁确保多实例部署时只有一个实例处理
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 20:54:37 -08:00
hailin
f7278b6196
feat(auth-service): 添加用户认证服务2.0
...
实现完整的用户认证服务,支持1.0用户迁移和2.0新用户注册:
功能特性:
- 用户注册(生成V2格式accountSequence: 15位)
- 密码登录(支持V1迁移用户和V2用户)
- V1用户首次登录自动迁移到2.0系统
- 短信验证码发送/验证(注册/登录/重置密码/更换手机号)
- 密码管理(重置密码、修改密码)
- KYC实名认证(提交/审核资料)
- JWT认证(Access Token + Refresh Token)
技术架构:
- DDD六边形架构(Domain/Application/Infrastructure/API)
- Prisma ORM + PostgreSQL
- CDC消费者同步1.0用户数据
- Outbox模式发布领域事件
- NestJS ThrottlerModule限流
数据模型:
- User: 2.0用户表(含KYC字段)
- SyncedLegacyUser: CDC同步的1.0用户(只读)
- RefreshToken: 刷新令牌
- SmsVerification: 短信验证码
- DailySequenceCounter: 每日序号计数器
- OutboxEvent: 发件箱事件
AccountSequence格式:
- V1: D + YYMMDD + 5位序号 = 12字符
- V2: D + YYMMDD + 8位序号 = 15字符
服务端口:3024
数据库:rwa_auth
同时更新deploy-mining.sh添加auth-service支持。
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-10 18:50:59 -08:00