fix(app): 移除已废弃的 uni.getUserProfile 调用修复首次登录失败
uni.getUserProfile 在微信基础库 2.27.1+ 已被移除,调用时抛出 TypeError 导致整个登录流程中断。新用户昵称由后端默认生成,用户可在资料页修改。 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -14,29 +14,11 @@ export async function wxLogin(): Promise<LoginResponse> {
|
|||||||
provider: 'weixin',
|
provider: 'weixin',
|
||||||
success: async (loginRes) => {
|
success: async (loginRes) => {
|
||||||
try {
|
try {
|
||||||
// Step 2: 获取用户微信头像和昵称
|
// Step 2: 发送登录请求
|
||||||
let nickname: string | undefined
|
// 注:uni.getUserProfile 已被微信废弃(基础库 2.27.1+),
|
||||||
let avatarUrl: string | undefined
|
// 新用户的昵称/头像由后端生成默认值,用户可在个人资料页修改
|
||||||
await new Promise<void>((res) => {
|
|
||||||
uni.getUserProfile({
|
|
||||||
desc: '用于完善个人资料',
|
|
||||||
success: (profileRes) => {
|
|
||||||
nickname = profileRes.userInfo.nickName
|
|
||||||
avatarUrl = profileRes.userInfo.avatarUrl
|
|
||||||
res()
|
|
||||||
},
|
|
||||||
fail: () => {
|
|
||||||
// 用户拒绝授权,仍可继续登录
|
|
||||||
res()
|
|
||||||
},
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
// Step 3: 发送登录请求
|
|
||||||
const result = await post<LoginResponse>('/auth/login', {
|
const result = await post<LoginResponse>('/auth/login', {
|
||||||
code: loginRes.code,
|
code: loginRes.code,
|
||||||
nickname,
|
|
||||||
avatarUrl,
|
|
||||||
})
|
})
|
||||||
uni.setStorageSync('token', result.token)
|
uni.setStorageSync('token', result.token)
|
||||||
resolve(result)
|
resolve(result)
|
||||||
|
|||||||
Reference in New Issue
Block a user