fix(login): 恢复手机号快捷登录功能,避免带旧Token导致失败
- 将 login.tsx 和 register.tsx 中登录请求从封装的 request 工具改回 Taro.request - 取消登录请求中自动注入 Authorization 头,避免携带过期/旧 token 导致认证失败 - 调整登录接口响应数据解析,适配 Taro.request 的数据结构 - fetchUserInfo 改回使用 Taro.request,手动携带 Authorization 头部 - 添加全局 getPhoneNumber 调用冷却机制,防止频繁调用导致微信报错 - 登录页新增手机授权冷却
This commit is contained in:
71
register_recover.patch
Normal file
71
register_recover.patch
Normal file
@@ -0,0 +1,71 @@
|
||||
--- a/src/passport/register.tsx 2026-07-16 15:55:24.000000000 +0800
|
||||
+++ b/src/passport/register.tsx 2026-07-16 15:54:30.000000000 +0800
|
||||
@@ -4,9 +4,8 @@
|
||||
import { Button, Checkbox } from '@nutui/nutui-react-taro'
|
||||
import { TenantId } from '@/config/app'
|
||||
import { getUserInfo, getWxOpenId } 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 {
|
||||
getStoredInviteParams,
|
||||
parseInviteParams,
|
||||
@@ -26,6 +25,17 @@
|
||||
detail: GetPhoneNumberDetail
|
||||
}
|
||||
|
||||
+interface LoginResponse {
|
||||
+ data: {
|
||||
+ code?: number
|
||||
+ message?: string
|
||||
+ data?: {
|
||||
+ access_token: string
|
||||
+ user: any
|
||||
+ }
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
async function getWeappLoginCode(): Promise<string | undefined> {
|
||||
try {
|
||||
const res = await new Promise<{ code?: string }>((resolve, reject) => {
|
||||
@@ -181,9 +191,10 @@
|
||||
// 获取小程序登录 code(用于后续绑定 openid)
|
||||
const wxLoginCode = await getWeappLoginCode()
|
||||
|
||||
- const res: any = await request.post(
|
||||
- `${SERVER_API_URL}/wx-login/loginByMpWxPhone`,
|
||||
- {
|
||||
+ const res = (await Taro.request({
|
||||
+ url: 'https://shop-api.websoft.top/api/wx-login/loginByMpWxPhone',
|
||||
+ method: 'POST',
|
||||
+ data: {
|
||||
code: phoneCode,
|
||||
encryptedData,
|
||||
iv,
|
||||
@@ -192,16 +203,19 @@
|
||||
sceneType: 'save_referee',
|
||||
tenantId: TenantId,
|
||||
},
|
||||
- { showError: false }
|
||||
- )
|
||||
+ header: {
|
||||
+ 'content-type': 'application/json',
|
||||
+ TenantId,
|
||||
+ },
|
||||
+ })) as unknown as LoginResponse
|
||||
|
||||
- if (res?.code === 1) {
|
||||
- Taro.showToast({ title: res.message || '登录失败', icon: 'none' })
|
||||
+ if ((res as any)?.data?.code === 1) {
|
||||
+ Taro.showToast({ title: res.data.message || '登录失败', icon: 'none' })
|
||||
return
|
||||
}
|
||||
|
||||
- const token = res?.data?.access_token
|
||||
- const user = res?.data?.user
|
||||
+ const token = res?.data?.data?.access_token
|
||||
+ const user = res?.data?.data?.user
|
||||
if (!token || !user?.userId) {
|
||||
Taro.showToast({ title: '登录失败,请重试', icon: 'none' })
|
||||
return
|
||||
Reference in New Issue
Block a user