Jack6
Jack6
  • 发布:2022-01-04 11:05
  • 更新:2022-01-04 15:34
  • 阅读:382

uni-cloud-router中一键登录会无限注册多个相同账号

分类:uniCloud
'use strict';  
const {  
    Router  
} = require('uni-cloud-router')  
const router = new Router(require('./config.js'))  
exports.main = async (event, context) => {  
    return router.serve(event, context)  
};  

通过uni-cloud-router中间件挂载的uniID进行一键登录,每次登录都会从新注册新账号,导致重复注册了多个相同账号,但没有报错,而且登录成功过后,前端db组件会报30204 | token校验未通过,只有通过非uni-cloud-router的云函数uniID登录,前端才不会报错30204

2022-01-04 11:05 负责人:无 分享
已邀请:
DCloud_uniCloud_WYQ

DCloud_uniCloud_WYQ

调用注册接口的代码发出来看看

  • Jack6 (作者)

    发在评论了,麻烦看看呢

    2022-01-04 11:32

Jack6

Jack6 (作者)

const loginLog = async (res = {}) => {  
        if (res.code != 0) {  
            return false  
        }  
        const now = Date.now()  
        const uniIdLogCollection = db.collection('uni-id-log')  
        let logData = {  
            deviceId: params.deviceId || ctx.context.DEVICEID,  
            ip: params.ip || ctx.context.CLIENTIP,  
            type: res.type,  
            ua: ctx.context.CLIENTUA,  
            create_date: now  
        };  

        Object.assign(logData,  
            res.code === 0 ? {  
                user_id: res.uid,  
                state: 1  
            } : {  
                state: 0  
            })  
        return await uniIdLogCollection.add(logData)  
    }  

let res;  
    switch (loginType) {  
        case 'loginByUniverify':  
            res = await ctx.uniID.loginByUniverify(params);  
            await loginLog(res);  
            break;  
        case 'loginByApple':  
            res = await ctx.uniID.loginByApple(params);  
            await loginLog(res);  
            break;  
        case 'loginByWeixin':  
            res = await ctx.uniID.loginByWeixin(params);  
            if (res.type == 'register') {  
                let newusername = "微信用户" + randomString("1", 6)  
                await ctx.uniID.updateUser({  
                    uid: res.uid,  
                    username: newusername  
                });  
                res.userInfo.username = newusername  
            }  
            await loginLog(res);  
            break;  
    }  
    console.log("=======登录-res: ==========", res);  
    if (res.code != 0) {  
        return res  
    }
Jack6

Jack6 (作者)

问题已解决,感谢DCloud_UNI_WYQ,远程给我解决了,uniID版本问题,更新到最新版本就正常了

该问题目前已经被锁定, 无法添加新回复