feat(email-smtp):update tags git

parent f75cd7d0
# SSO VietProDev — Database Cleanup & Redesign # SSO VietProDev — Database Cleanup & Redesign
**Date:** 2026-06-18 **Date:** 2026-06-18
**Status:** Analysis Complete — Ready for Implementation **Status:** ✅ Fully Implemented (sessions 4 + 5, 2026-06-20)
--- ---
...@@ -227,33 +227,23 @@ Contracts to DELETE: ...@@ -227,33 +227,23 @@ Contracts to DELETE:
--- ---
## 7. Immediate Action Items ## 7. Implementation Summary
### 1. Fix crash (quick fix)
In `src/server.ts`, wrap `MultiPoolService.autoLoadPools()` in a check:
```typescript
// Skip if project_db_connections table doesn't exist
try {
await MultiPoolService.autoLoadPools();
} catch (poolErr) {
log('WARN', `autoLoadPools skipped: ${poolErr}`);
}
```
Or modify `multiPoolService.ts` to check table existence first.
### 2. Fix Swagger title All Option A (Full Cleanup) items have been implemented:
Run `pnpm swagger:generate` after updating the project name in contracts.
### 3. Decide cleanup scope -`MultiPoolService` — graceful skip when `project_db_connections` missing
- **New project (fresh start):** Use Option A — delete all legacy domain modules - ✅ Swagger — regenerated as "SSO VietProDev API" (50 paths)
- **Incremental:** Use Option B — just fix branding and regenerate Swagger - ✅ All 27 legacy models deleted (residents, beds, bills, contracts, incidents, etc.)
- ✅ All 18 legacy controllers deleted
- ✅ All 17 legacy contracts deleted
-`init-models.ts` rewritten (33 models, 297 lines)
- ✅ Legacy services deleted (webhookService, residentExcelService, etc.)
- ✅ BeKind residue cleaned from all source files
-`clean-migration.sql` rewritten (1063 lines, SSO-only enums)
-`npx tsc --noEmit` → exit 0
-`pnpm swagger:generate` → 50 SSO paths
### 4. Deploy clean migration **Implementation details:** See PROGRESS.md §17 (session 4).
```bash
# Drop all existing tables and run clean migration
psql "$DATABASE_URL" -f sql/clean-migration.sql
```
--- ---
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
> Roadmap tổng thể dự án: kiến trúc, hướng đi, refactor, cleanup, test plan. > Roadmap tổng thể dự án: kiến trúc, hướng đi, refactor, cleanup, test plan.
> >
> **Trạng thái:** DRAFT (chờ user confirm trước khi implement) > **Trạng thái:** Active Development
> **Ngày tạo:** 2026-06-18 > **Ngày tạo:** 2026-06-18
> **Cập nhật lần cuối:** 2026-06-18 > **Cập nhật lần cuối:** 2026-06-22
--- ---
...@@ -532,13 +532,37 @@ Hoặc đơn giản hơn Phase đầu: **mỗi project tự lưu session riêng* ...@@ -532,13 +532,37 @@ Hoặc đơn giản hơn Phase đầu: **mỗi project tự lưu session riêng*
| Phase | Status | Started | Completed | Notes | | Phase | Status | Started | Completed | Notes |
|-------|--------|---------|-----------|-------| |-------|--------|---------|-----------|-------|
| 0 | 🟡 Ready to start | — | — | Đã chốt decisions trong §4. Đợi user confirm để bắt đầu. | | 0 | 🟢 Done | 2026-06-18 | 2026-06-20 | Cleanup + foundation |
| 1 | ⚪ Not started | — | — | Phụ thuộc Phase 0 | | 1 | 🟢 Done | 2026-06-18 | 2026-06-22 | Wire OIDC Login — full end-to-end working |
| 2 | ⚪ Not started | — | — | Phụ thuộc Phase 1 | | 2 | 🟡 Partial | 2026-06-22 | — | prompt=none pending; logout cross-client fixed |
| 3 | ⚪ Not started | — | — | Phụ thuộc Phase 2 | | 3 | ⚪ Not started | — | — | HA + Audit |
| 4 | ⚪ Not started | — | — | Phụ thuộc Phase 3 | | 4 | ⚪ Not started | — | — | Production readiness |
Legend: 🔴 Pending | 🟡 In progress | 🟢 Done | ⚪ Not started **Phase 1 — All Complete (2026-06-22):**
- [x] Wire `validateCredentials` — real user lookup + password verify + status guard
- [x] OIDC flow end-to-end — register → verify → login → consent → token exchange → userinfo
- [x] `findAccount.claims()` — returns full user claims (name, email, email_verified, preferred_username)
- [x] Logout flow — "No, stay signed in" redirects to correct client
- [x] Logout flow — `postLogoutSuccessSource` uses query params (survives session destroy)
- [x] Both demo apps working (project-a 4001, project-b 4002)
**Phase 2 remaining:**
- [ ] `prompt=none` (silent SSO) — project-b auto-login when session exists
- [ ] Remember consent — skip consent page for previously approved scopes
- [ ] Front-channel / back-channel logout
**Phase 3 remaining:**
- [ ] MultiPoolService autoLoadPools
- [ ] MongoDB audit strategy
- [ ] Failover logic
**Phase 4 remaining:**
- [ ] CSRF protection
- [ ] Rate limiting
- [ ] HTTPS redirect
- [ ] Production secrets
Legend: 🟢 Done | 🟡 Partial | ⚪ Not started
--- ---
......
...@@ -918,10 +918,49 @@ pnpm swagger:generate ...@@ -918,10 +918,49 @@ pnpm swagger:generate
pnpm dev pnpm dev
# → http://localhost:3001/swagger/index/ # → http://localhost:3001/swagger/index/
``` ```
--- ---
## Session 5 — Bug Audit, Cleanup & Refactor (2026-06-20) ## §18 — Session 5: Bug Audit, Cleanup & Refactor (2026-06-20)
### Bugs fixed
**1. User info returns `Unknown` / missing email in demo apps**
`oidcService.ts` — `findAccount.claims()` chỉ trả về `{ sub }`. Sửa để lấy đầy đủ user claims từ database:
```ts
claims: () => ({
sub,
...(user?.email ? { email: user.email } : {}),
...(user?.email_verified_at != null ? { email_verified: true } : { email_verified: false }),
...(fullName ? { name: fullName } : {}),
...(user?.username ? { preferred_username: user.username } : {}),
})
```
**2. Logout "No, stay signed in" redirects to wrong app (Project A instead of Project B)**
Vấn đề root cause: `client_id` không được gửi trong form body → `resolveRedirectUri` nhận `clientId=undefined` → fallback về `http://localhost:4001` (Project A).
Fixes:
- `oidcService.ts``logoutFormHtml`: thêm `<input type="hidden" name="client_id" value="${clientId}" />` vào form.
- `logoutSource`: truyền `clientId` vào form.
- `oidcRoutes.ts` — POST `/oauth/logout/confirm`: đọc `client_id` từ `req.body` (ưu tiên `req.query`).
**3. `postLogoutSuccessSource` redirect fails after session destroy**
Sau khi logout confirmed, session bị destroy trước khi `postLogoutSuccessSource` chạy → `ctx.oidc.session?.state?.postLogoutRedirectUri` bị undefined → fallback về logout-success page.
Fix: Dùng `ctx.oidc.params.post_logout_redirect_uri` (query string, tồn tại sau session destroy) thay vì `ctx.oidc.session.state.postLogoutRedirectUri`. Validate URI với registered `postLogoutRedirectUris` của client trước khi redirect.
### Verification
- `npx tsc --noEmit` → exit 0
- OIDC flow: register → verify → login → consent → token exchange → userinfo trả về đầy đủ `{ sub, name, preferred_username, email, email_verified }`
- Logout Project B → "No, stay signed in" → redirect về Project B (4002) ✅
- Logout Project B → "Yes, sign out" → redirect về Project B ✅
- Logout Project A → "No, stay signed in" → redirect về Project A (4001) ✅
Comprehensive audit + cleanup pass on top of the SSO core. `tsc --noEmit` clean; OpenAPI regenerates; smoke-tested against the running dev server. Comprehensive audit + cleanup pass on top of the SSO core. `tsc --noEmit` clean; OpenAPI regenerates; smoke-tested against the running dev server.
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment