feat: switch to global auth and tenant route prefix
This commit is contained in:
101
docs/plan.md
101
docs/plan.md
@@ -0,0 +1,101 @@
|
||||
# Implementation Plan: Global Auth + Tenant Route Prefix
|
||||
|
||||
**Branch**: `main` | **Date**: 2026-01-26 | **Spec**: N/A
|
||||
**Input**: 改为全局登录;租户资源访问再鉴权;后端路由从 `/t/:tenantCode/v1` 改为 `/v1/t/:tenantCode`,同步前端路由。
|
||||
|
||||
**Note**: 本计划遵循 `docs/templates/plan-template.md`。
|
||||
|
||||
## Summary
|
||||
|
||||
实施全局登录(不要求 tenantCode),并将多租户路由前缀统一为 `/v1/t/:tenantCode`。同步更新后端路由与前端路由/请求封装,确保登录与资源鉴权一致。
|
||||
|
||||
## Technical Context
|
||||
|
||||
**Language/Version**: Go 1.22 + Vue 3 (Vite)
|
||||
**Primary Dependencies**: Fiber, GORM-Gen, Vue Router
|
||||
**Storage**: PostgreSQL
|
||||
**Testing**: go test / 前端 build+l int(如需)
|
||||
**Target Platform**: local/staging
|
||||
**Project Type**: Web application
|
||||
**Performance Goals**: N/A
|
||||
**Constraints**: 不改生成文件,需通过 `atomctl` 重新生成路由/Swagger
|
||||
**Scale/Scope**: auth + 路由前缀调整
|
||||
|
||||
## Constitution Check
|
||||
|
||||
- 遵循 `backend/llm.txt`(控制器薄、服务层处理、生成文件不手改)
|
||||
- 变更后需跑 `atomctl gen route/provider/swag`
|
||||
|
||||
## Project Structure
|
||||
|
||||
### Backend
|
||||
|
||||
```text
|
||||
backend/app/http/v1/
|
||||
backend/app/services/
|
||||
backend/app/http/**/routes.*.go
|
||||
```
|
||||
|
||||
### Frontend
|
||||
|
||||
```text
|
||||
frontend/portal/src/router/index.js
|
||||
frontend/portal/src/utils/request.js
|
||||
frontend/portal/src/api/*
|
||||
frontend/superadmin/src/router/index.js
|
||||
```
|
||||
|
||||
### Docs
|
||||
|
||||
```text
|
||||
docs/plan.md
|
||||
```
|
||||
|
||||
## Plan Phases
|
||||
|
||||
### Phase 1: Backend route + auth changes
|
||||
- 调整 `/t/:tenantCode/v1` 为 `/v1/t/:tenantCode`
|
||||
- 登录逻辑改为全局登录(租户鉴权移到资源访问)
|
||||
|
||||
### Phase 2: Frontend route + request changes
|
||||
- 更新 portal 路由基座与 request baseUrl
|
||||
- 更新所有前端 API 路径对应新前缀
|
||||
|
||||
### Phase 3: Regenerate + sanity check
|
||||
- 生成 routes/providers/swagger
|
||||
- 关键页面手动/自动冒烟校验
|
||||
|
||||
## Tasks
|
||||
|
||||
**Format**: `[ID] [P?] [Story] Description`
|
||||
|
||||
### Phase 1
|
||||
- [ ] T001 [US0] 修改后端路由前缀与路由注册
|
||||
- [ ] T002 [US0] 调整登录逻辑为全局登录
|
||||
|
||||
### Phase 2
|
||||
- [ ] T010 [US1] 修改 portal 路由与 request baseUrl
|
||||
- [ ] T011 [US1] 更新 portal API 路径
|
||||
|
||||
### Phase 3
|
||||
- [ ] T020 [US2] 重新生成路由与 swagger
|
||||
- [x] T021 [US2] 冒烟验证核心路径
|
||||
|
||||
## Dependencies
|
||||
|
||||
- Phase 1 → Phase 2 → Phase 3
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
- 登录不依赖 tenantCode。
|
||||
- 租户路由统一为 `/v1/t/:tenantCode`。
|
||||
- Portal 页面正常加载并可登录。
|
||||
|
||||
## Risks
|
||||
|
||||
- 大量前端 API 路径需要同步改动。
|
||||
- 老路径可能被外部依赖使用。
|
||||
|
||||
## Complexity Tracking
|
||||
|
||||
无。
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
## Service Startup (Local)
|
||||
|
||||
- Backend: `go run ./backend/main.go serve` (default `http://localhost:8080`).
|
||||
- Portal frontend: `npm -C frontend/portal install` then `npm -C frontend/portal run dev` (default `http://localhost:5174`).
|
||||
- Superadmin frontend: `npm -C frontend/superadmin install` then `npm -C frontend/superadmin run dev` (default `http://localhost:5173`).
|
||||
- Portal frontend: `npm -C frontend/portal install` then `npm -C frontend/portal run dev` (default `http://localhost:5174`, remote use `http://10.1.1.104:5174`).
|
||||
- Superadmin frontend: `npm -C frontend/superadmin install` then `npm -C frontend/superadmin run dev` (default `http://localhost:5173`, remote use `http://10.1.1.104:5173`).
|
||||
- Portal dev server proxies `/v1` to `http://localhost:8080` (`frontend/portal/vite.config.js`).
|
||||
- Superadmin dev server proxies `/super/v1` and `/v1` to `http://localhost:8080` (`frontend/superadmin/vite.config.mjs`).
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
### MCP Example Flow (AI Guidance)
|
||||
|
||||
1. **Open Portal Home**
|
||||
- `chrome-devtools_new_page` → `http://localhost:5174/t/:tenantCode`
|
||||
- `chrome-devtools_new_page` → `http://10.1.1.104:5174/t/:tenantCode`
|
||||
- `chrome-devtools_wait_for` text: `探索戏曲` or page title
|
||||
|
||||
2. **Portal Login**
|
||||
@@ -50,7 +50,7 @@
|
||||
- Assert detail page loads and cover/media is visible
|
||||
|
||||
5. **Superadmin Login**
|
||||
- `chrome-devtools_new_page` → `http://localhost:5173/super/auth/login`
|
||||
- `chrome-devtools_new_page` → `http://10.1.1.104:5173/super/auth/login`
|
||||
- Fill `#username` with `superadmin` and `#password1` with `superadmin123`
|
||||
- Click `Sign In`
|
||||
- Wait for dashboard cards or `Dashboard` text
|
||||
@@ -80,7 +80,7 @@
|
||||
|
||||
## Portal Smoke (Use tenantCode)
|
||||
|
||||
- Tenant code: query DB (`SELECT code FROM tenants ORDER BY id DESC LIMIT 1;`), then open `http://localhost:5174/t/:tenantCode`.- Login: OTP is fixed to `1234` (see `backend/app/services/user.go`).
|
||||
- Tenant code: query DB (`SELECT code FROM tenants ORDER BY id DESC LIMIT 1;`), then open `http://10.1.1.104:5174/t/:tenantCode`.- Login: OTP is fixed to `1234` (see `backend/app/services/user.go`).
|
||||
- Home: `/t/:tenantCode` lists content.
|
||||
- Detail: open any content detail; cover and main asset render.
|
||||
- Login: sign in as `test` (phone `13800138000`, OTP `1234`) and open `/t/:tenantCode/me`.
|
||||
|
||||
Reference in New Issue
Block a user