feat: 微信分享钩子全页面接入 + 订阅信息结构化映射 + JWT 错误处理加强

- client: 全部页面接入 onShareAppMessage/onShareTimeline 分享钩子
- client: login 页增强、profile 订阅展示优化
- client/stores: 订阅字段扁平结构映射为 subInfo(plan/expiresAt/startDate)
- server: auth 路由 JWT 无效/过期统一返回 401 未授权响应
- server: models/tests 同步更新
This commit is contained in:
Yuzhiran Dev
2026-09-04 11:47:29 +08:00
parent de8ca9c420
commit 66de1dc396
37 changed files with 2138 additions and 1830 deletions
+19 -7
View File
@@ -36,18 +36,33 @@ export const useUserStore = defineStore('user', () => {
return data
}
async function h5Register(email, password, nickName, verifyCode) {
const data = await authApi.register(email, password, nickName, verifyCode)
async function h5Register(email, password, nickName, verifyCode, username) {
const data = await authApi.register(email, password, nickName, verifyCode, username)
token.value = data.token
userInfo.value = data.userInfo
uni.setStorageSync('token', data.token)
return data
}
// 将后端扁平的订阅字段映射为前端使用的 subInfo 结构
function mapSubscription(u) {
if (!u) return null
const isSub = !!u.isSubscriber
const expires = u.subscribeExpiry || null
if (!isSub && !expires) return null
return {
plan: u.subscriptionPlan || (isSub ? 'PRO' : 'free'),
expiresAt: expires,
startDate: u.subscribeStart || u.createdAt || null
}
}
async function fetchMe() {
try {
const data = await authApi.me(token.value)
userInfo.value = data
// /me 返回完整用户文档,直接派生订阅信息
subInfo.value = mapSubscription(data)
return data
} catch (err) {
console.error('[userStore] fetchMe failed:', err)
@@ -56,14 +71,11 @@ export const useUserStore = defineStore('user', () => {
}
async function fetchSubInfo(tokenVal) {
// 从后端获取订阅信息 - 复用 knowledgeApi 或专门接口
// 当前后端无单独订阅接口,从 /api/user/progress 中获取
const { userApi } = await import('@/utils/api')
try {
const progress = await userApi.progress(tokenVal)
if (progress && progress.subscription) {
subInfo.value = progress.subscription
}
const u = progress && (progress.data || progress)
subInfo.value = mapSubscription(u)
} catch (err) {
console.error('[userStore] fetchSubInfo failed:', err)
}