uni-app uni-quick-login插件 Apple首次登录user id未存入userInfo里

uni-app uni-quick-login插件 Apple首次登录user id未存入userInfo里

开发环境 版本号 项目创建方式
Mac Monterey HBuilderX

产品分类:uniapp/App

PC开发环境操作系统:Mac

PC开发环境操作系统版本号:Monterey

HBuilderX类型:Alpha

HBuilderX版本号:3.3.2

手机系统:iOS

手机系统版本号:iOS 15

手机厂商:苹果

手机机型:iphone13

页面类型:vue

vue版本:vue2

打包方式:云端

项目创建方式:HBuilderX

示例代码:

uniCloud.callFunction({  
    name: 'uni-id-cf',  
    data: {  
        action,  
        params  
    },  
    success: async ({  
        result  
    }) => {  
        console.log("login-result", result);  
        if (result.code === 0) {  
            if (type == 'univerify') {  
                uni.closeAuthView()  
            }  
            uni.hideLoading()  
            delete result.userInfo.token  

            // #ifdef MP-WEIXIN  
            if (type == 'weixin' && !result.userInfo.nickname) {  
                return this.$refs.userProfile.open(result.uid)  
            }  
            // #endif  

            this.setUserInfo(result.userInfo)  
            loginSuccess(result)  
        } else {  
            uni.showModal({  
                content: result.msg,  
                showCancel: false  
            });  
        }  
    },  
    complete: () => {  
        uni.hideLoading()  
    }  
})

问题就在这行 this.setUserInfo(result.userInfo)

apple 首次登陆后的result里面uid并不在userInfo里.

实例:

{
    "code": 0,
    "msg": "注册成功",
    "token": "x x x",
    "tokenExpired": 1642923821777,
    "uid": "uid在这个层级",
    "type": "register",
    "userInfo": {
        "nickname": "xxx",
        "apple_openid": "xxx",
        "dcloud_appid": ["xxx"],
        "register_date": 1640331821575,
        "register_ip": "192.168.31.177",
        "token": "xxx"
    },
    "openid": "xxx",
    "errCode": 0,
    "errMsg": "注册成功",
    "message": "注册成功"
}

操作步骤:

新用户用apple login首次登陆

预期结果:

新用户用apple login首次登陆后用户id会存放在userInfo里面

实际结果:

新用户用apple login首次登陆后用户id会没存放在userInfo里面, 导致其他功能失效

bug描述:

Apple首次登陆user id不会存到userInfo

  1. 新用户, 用apple首次登陆之后功能异常, 重新登陆后正常.
  2. debug的结论是因为首次登陆后user id没有存放在userInfo
  3. 具体code在

更多关于uni-app uni-quick-login插件 Apple首次登录user id未存入userInfo里的实战教程也可以访问 https://www.itying.com/category-93-b0.html

3 回复

if (type == ‘apple’) {
result.userInfo._id = result.uid
} 加上这一行就好了

更多关于uni-app uni-quick-login插件 Apple首次登录user id未存入userInfo里的实战教程也可以访问 https://www.itying.com/category-93-b0.html


应当是判断 result.type == “register” 感谢反馈,1.1.26版本的uni-starter将修复此问题。

这是一个关于uni-app中uni-quick-login插件在Apple首次登录时uid未存入userInfo的问题。根据你提供的代码和日志,确实可以看到uid是在返回结果的顶层,而不是在userInfo对象中。

解决方案很简单,在调用setUserInfo之前,需要手动将uid合并到userInfo对象中:

if (result.code === 0) {
    if (type == 'univerify') {
        uni.closeAuthView()
    }
    uni.hideLoading()
    delete result.userInfo.token
    
    // 将uid合并到userInfo中
    if(result.uid && !result.userInfo._id) {
        result.userInfo._id = result.uid
    }
    
    // #ifdef MP-WEIXIN
    if (type == 'weixin' && !result.userInfo.nickname) {
        return this.$refs.userProfile.open(result.uid)
    }
    // #endif
    
    this.setUserInfo(result.userInfo)
    loginSuccess(result)
}
回到顶部