fix(mp): inject-auth 清除 _es_ 旧加密值,避免 secureGet 读到过期 token

inject_auth 写入明文 storage 键但不清除 _es_ 前缀的旧加密值,
导致 secureGet 优先读到旧的/过期的加密 token,所有 API 请求 401。
修复:写入前先 removeStorageSync 所有 _es_ 前缀键。
This commit is contained in:
iven
2026-05-21 18:23:46 +08:00
parent bc571c7749
commit f59e40e6fe

View File

@@ -35,8 +35,10 @@ async function main() {
console.log('3. 写入 storage (明文模式)...');
const result = await mp.evaluate((at, rt, ud, ur, tid, pid) => {
try {
// 无加密密钥时 secureSet 走明文
// 但我们直接用 wx.setStorageSync 确保
// 清除 _es_ 前缀旧加密值,避免 secureGet 读到过期 token
['access_token','refresh_token','user_data','user_roles','tenant_id','current_patient_id','current_patient','token_expires_at'].forEach(k => {
wx.removeStorageSync('_es_' + k);
});
wx.setStorageSync('access_token', at);
wx.setStorageSync('refresh_token', rt);
wx.setStorageSync('user_data', ud);