Files
xinlong-shop-taro/login_recover.patch
赵忠林 46298c011f fix(login): 恢复手机号快捷登录功能,避免带旧Token导致失败
- 将 login.tsx 和 register.tsx 中登录请求从封装的 request 工具改回 Taro.request
- 取消登录请求中自动注入 Authorization 头,避免携带过期/旧 token 导致认证失败
- 调整登录接口响应数据解析,适配 Taro.request 的数据结构
- fetchUserInfo 改回使用 Taro.request,手动携带 Authorization 头部
- 添加全局 getPhoneNumber 调用冷却机制,防止频繁调用导致微信报错
- 登录页新增手机授权冷却
2026-07-16 17:01:17 +08:00

91 lines
3.0 KiB
Diff
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

--- a/src/passport/login.tsx 2026-07-16 15:54:54.000000000 +0800
+++ b/src/passport/login.tsx 2026-07-16 15:53:09.000000000 +0800
@@ -4,9 +4,8 @@
import { TenantId } from '@/config/app'
import { getWxOpenId } from '@/api/layout'
import { getUserInfo } from '@/api/layout'
-import { saveStorageByLoginUser, SERVER_API_URL } from '@/utils/server'
+import { saveStorageByLoginUser } from '@/utils/server'
import { isUserDisabled } from '@/utils/auth'
-import request from '@/utils/request'
import {
checkAndHandleInviteRelation,
hasPendingInvite,
@@ -73,21 +72,22 @@
}
}
-/** 获取用户信息(使用临时 token避免本地 storage 尚未写入) */
+/** 获取用户信息 */
async function fetchUserInfo(token: string) {
try {
- const res: any = await request.get(
- `${SERVER_API_URL}/auth/user`,
- {},
- {
- header: {
- Authorization: `Bearer ${token}`,
- },
- showError: false,
- }
- )
- if (res?.code === 0 && res?.data) {
- return res.data
+ const serverUrl = 'https://server.websoft.top'
+ const res: any = await Taro.request({
+ url: `${serverUrl}/api/auth/user`,
+ method: 'GET',
+ header: {
+ Authorization: `Bearer ${token}`,
+ 'content-type': 'application/json',
+ TenantId: String(TenantId),
+ },
+ })
+
+ if (res.data?.code === 0 && res.data?.data) {
+ return res.data.data
}
return null
} catch (e) {
@@ -215,21 +215,23 @@
const inviteParams = parseInviteParams({ query: router?.params })
const refereeId = inviteParams?.inviter ? parseInt(inviteParams.inviter, 10) : 0
- const res: any = await request.post(
- `${SERVER_API_URL}/wx-login/loginByMpWxPhone`,
- {
+ const serverUrl = 'https://server.websoft.top'
+ const res: any = await Taro.request({
+ url: `${serverUrl}/api/wx-login/loginByMpWxPhone`,
+ method: 'POST',
+ data: {
code: phoneCode,
notVerifyPhone: true,
refereeId,
sceneType: 'save_referee',
tenantId: Number(TenantId),
},
- { showError: false }
- )
+ header: { 'content-type': 'application/json', TenantId: String(TenantId) },
+ })
- if (res?.code === 0 && res?.data?.access_token) {
- const token = res.data.access_token
- let user = res.data.user
+ if (res.data?.code === 0 && res.data?.data?.access_token) {
+ const token = res.data.data.access_token
+ let user = res.data.data.user
// 获取最新的用户信息
const freshUserInfo = await fetchUserInfo(token)
@@ -260,7 +262,7 @@
Taro.showToast({ title: '登录成功', icon: 'success' })
setTimeout(() => navigateAfterLogin(), 800)
} else {
- Taro.showToast({ title: res?.message || '登录失败', icon: 'none' })
+ Taro.showToast({ title: res.data?.message || '登录失败', icon: 'none' })
}
} catch (e: any) {
console.error('微信登录失败:', e)