From c314093c766afbd673de1bfae6e038adca1524d4 Mon Sep 17 00:00:00 2001 From: iven Date: Mon, 27 Apr 2026 08:20:12 +0800 Subject: [PATCH] =?UTF-8?q?fix(miniprogram):=20auth=20store=20restore()=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20+=20=E5=BC=80=E5=90=AF=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96=E7=AB=AF=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - restore() 从 Taro.getStorageSync 改为 secureGet 读取加密数据 - 修复 key 不匹配: 'user' → 'user_data', 'user_roles' → 'user_roles' - login 写入 secureSet('user_data') 但 restore 读 Taro.getStorageSync('user') - 导致每次 app 重启都无法恢复登录状态 - project.config.json 开启 automationAudits 以支持 miniprogram-automator --- apps/miniprogram/project.config.json | 14 ++++++++------ apps/miniprogram/src/stores/auth.ts | 10 ++++++++-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/apps/miniprogram/project.config.json b/apps/miniprogram/project.config.json index da4cd7d..2454a3c 100644 --- a/apps/miniprogram/project.config.json +++ b/apps/miniprogram/project.config.json @@ -3,12 +3,14 @@ "miniprogramRoot": "dist/", "compileType": "miniprogram", "setting": { - "autoAudits": false, "urlCheck": false, - "es6": true, - "enhance": true, + "automationAudits": true, + "es6": false, + "enhance": false, "compileHotReLoad": true, - "postcss": true, - "minified": true + "postcss": false, + "minified": false, + "bundle": false, + "minifyWXML": true } -} +} \ No newline at end of file diff --git a/apps/miniprogram/src/stores/auth.ts b/apps/miniprogram/src/stores/auth.ts index 9f71bb4..5970921 100644 --- a/apps/miniprogram/src/stores/auth.ts +++ b/apps/miniprogram/src/stores/auth.ts @@ -43,8 +43,14 @@ export const useAuthStore = create((set, get) => ({ }, restore: () => { - const user = Taro.getStorageSync('user') || null; - const roles = Taro.getStorageSync('user_roles') || []; + let user: AuthState['user'] = null; + let roles: string[] = []; + try { + const userData = secureGet('user_data'); + if (userData) user = JSON.parse(userData); + const rolesData = secureGet('user_roles'); + if (rolesData) roles = JSON.parse(rolesData); + } catch { /* secure storage 不可用时保持默认值 */ } const currentPatient = Taro.getStorageSync('current_patient') || null; set({ user, roles, currentPatient }); },