fix: 修复会话鉴权「登录后 token 无效」并补齐 NAS 部署流程
- deps.py: _create_redis_client 增加同步 ping 校验,Redis 不可达时正确降级为内存模式 - main.py: lifespan 复用 deps 的 UserStore 单例,避免 admin 与 API 请求实例不一致 - 前端: 强制改密弹窗(must_change_password 用户)、兼容新旧登录返回格式、markPasswordChanged - 新增 NAS SSH 部署脚本与批处理测试;gitignore 前端构建产物
This commit is contained in:
@@ -39,13 +39,27 @@ export const useAuthStore = defineStore('auth', {
|
||||
actions: {
|
||||
/**
|
||||
* 登录成功后保存 token + user
|
||||
* @param {{access_token:string, user:object}} data
|
||||
* 兼容后端两种返回:
|
||||
* - 新格式 { token, username, role, must_change_password }
|
||||
* - 旧格式 { access_token, user: { username, role, ... } }
|
||||
* @param {object} data
|
||||
*/
|
||||
setAuth(data) {
|
||||
this.token = data.access_token
|
||||
this.user = data.user
|
||||
localStorage.setItem(TOKEN_STORAGE_KEY, data.access_token)
|
||||
localStorage.setItem(USER_STORAGE_KEY, JSON.stringify(data.user))
|
||||
const token = data?.access_token ?? data?.token
|
||||
const user =
|
||||
data?.user ??
|
||||
(data
|
||||
? {
|
||||
username: data.username,
|
||||
role: data.role,
|
||||
must_change_password: data.must_change_password ?? false
|
||||
}
|
||||
: null)
|
||||
if (!token || !user) return
|
||||
this.token = token
|
||||
this.user = user
|
||||
localStorage.setItem(TOKEN_STORAGE_KEY, token)
|
||||
localStorage.setItem(USER_STORAGE_KEY, JSON.stringify(user))
|
||||
},
|
||||
|
||||
/** 清除登录态(登出 / 401) */
|
||||
@@ -56,6 +70,13 @@ export const useAuthStore = defineStore('auth', {
|
||||
localStorage.removeItem(USER_STORAGE_KEY)
|
||||
},
|
||||
|
||||
/** 改密成功后更新本地用户状态(清除 must_change_password 标记) */
|
||||
markPasswordChanged() {
|
||||
if (!this.user) return
|
||||
this.user = { ...this.user, must_change_password: false }
|
||||
localStorage.setItem(USER_STORAGE_KEY, JSON.stringify(this.user))
|
||||
},
|
||||
|
||||
/**
|
||||
* 登出
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user