fix(mp): 微信登录 API 失败时不应显示手机绑定按钮
根因:login() 的 catch 块把所有错误都返回 false, 导致 handleWechatLogin 误判为'未绑定'并显示手机绑定按钮。 用户点击绑定后因 wechat_openid 从未写入而报'登录态丢失'。 修复: - API 失败时 throw 而非 return false,让调用方区分错误和未绑定 - 增加 resp.openid 空值校验,防止后端返回空 openid 进入绑定流程 - 现在后端不可用时用户会看到正确的错误提示而非误导性的绑定按钮
This commit is contained in:
@@ -148,13 +148,19 @@ export const useAuthStore = create<AuthState>((set, get) => ({
|
||||
get().loadPatients();
|
||||
return true;
|
||||
}
|
||||
// 未绑定:存储 openid 供后续绑定流程使用
|
||||
if (!resp.openid) {
|
||||
set({ loading: false });
|
||||
throw new Error('登录失败:服务器未返回用户标识');
|
||||
}
|
||||
secureSet('wechat_openid', resp.openid);
|
||||
set({ loading: false });
|
||||
return false;
|
||||
} catch (err) {
|
||||
console.warn('[auth] 微信登录失败:', err);
|
||||
set({ loading: false });
|
||||
return false;
|
||||
// 不吞掉错误 — 让调用方区分"未绑定"和"真正的错误"
|
||||
throw err;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user