tencentyun / wafer2-node-sdk

Wafer2 SDK for Node.js
Other
268 stars 58 forks source link

authorization (req) 似乎有个逻辑bug #56

Closed GMIS closed 6 years ago

GMIS commented 6 years ago
if (code && !encryptedData && !iv) {
        return getSessionKey(code).then(pkg => {
            const { openid, session_key } = pkg
            // 生成 3rd_session
            const skey = sha1(session_key)

            return AuthDbService.getUserInfoByOpenId(openid).then(userinfo => {
                const wxUserInfo = JSON.parse(userinfo.user_info)

                return AuthDbService.saveUserInfo(wxUserInfo, skey, session_key)
                .then(userinfo => ({
                    loginState: LOGIN_STATE.SUCCESS,
                    userinfo: {
                        userinfo: wxUserInfo,
                        skey: userinfo.skey
                    }
                }))
            })
        })
    }

代码中getUserInfoByOpenId()先于saveUserInfo()使用,那么其中getUserInfoByOpenId()返回的userinfo很可能是undefined,我就遇到这种情况。

jas0ncn commented 6 years ago

这个接口要求已经登录过的调用,已经登录过 userinfo 不会为空

maxcheers86 commented 5 years ago