fix(auth): transfer WeChat id on merge; stop false phone prompts
CI / verify (pull_request) Has been cancelled

Merge used to drop wxOpenId so OAuth created a new guest without phone every time. Now migrate WeChat identity, recover legacy merged openIds, return accountMerged and force page reload, and only soft-prompt when phone is truly unbound.
This commit is contained in:
2026-07-15 21:25:34 +08:00
parent 5c55d3c385
commit d3d56150c5
7 changed files with 229 additions and 14 deletions
+43
View File
@@ -70,3 +70,46 @@ export function finishLoginNavigate(returnTo?: string) {
Taro.reLaunch({ url: '/pages/home/index' });
}
/**
* 账号合并后强制整页刷新,避免旧会话栈 / 旧用户缓存继续提示绑定手机号。
* H5:按当前路径推算出落地 URL 后 location.replace;小程序:reLaunch。
*/
export function forceReloadAfterAccountMerge(returnTo?: string) {
const raw = (returnTo || '').trim();
let target = '';
try {
target = raw ? decodeURIComponent(raw) : '';
} catch {
target = raw;
}
const pathOnly = target.split('?')[0];
const safePath =
pathOnly && pathOnly.startsWith('/pages/') && !pathOnly.includes('/pages/login')
? target
: '/pages/home/index';
const launchPath = safePath.split('?')[0];
if (process.env.TARO_ENV === 'h5' && typeof window !== 'undefined') {
const { origin, pathname, search } = window.location;
const marker = '/pages/';
const idx = pathname.indexOf(marker);
let href: string;
if (idx >= 0) {
href = `${origin}${pathname.slice(0, idx)}${safePath}`;
} else if (window.location.hash.includes('/pages/')) {
href = `${origin}${pathname}${search}#${safePath}`;
} else {
const base = pathname.replace(/\/$/, '') || '';
href = `${origin}${base}${safePath.startsWith('/') ? safePath : `/${safePath}`}`;
}
window.location.replace(href);
return;
}
if (TAB_PAGES.has(launchPath)) {
Taro.reLaunch({ url: launchPath });
return;
}
Taro.reLaunch({ url: safePath.startsWith('/') ? safePath : `/${safePath}` });
}