fix(login): noMobile 阶段后端将 openId 放 bindKey 字段返回,纳入兜底链

This commit is contained in:
ozh 2026-09-16 15:15:48 +08:00
parent 34a3887b2d
commit 10905df143
1 changed files with 5 additions and 2 deletions

View File

@ -36,8 +36,11 @@ export default function Login() {
const state = getLoginSubState(result)
if (state !== 'complete') {
console.log('[login-page] 注册未完成,推进到', state)
// noMobile 响应可能不回传 openId(首次 needUserInfo 已缓存本地),从 storage 兜底
const openIdNext = result.openId ?? storage.get<string>(WX_OPENID_STORAGE_KEY) ?? openId
// openId 兜底链:noMobile 阶段后端把 openId 放在 bindKey 字段返回(联调实测);
// 其余阶段从本地缓存(needUserInfo 时已写入)兜底
const openIdNext =
result.openId ?? (state === 'noMobile' ? result.bindKey : undefined) ??
storage.get<string>(WX_OPENID_STORAGE_KEY) ?? openId
if (!openIdNext) throw new Error('响应缺少 openId,无法继续授权')
setOpenId(openIdNext)
setSubState(state)