const uniID = require('uni-id-common')
// const db = uniCloud.database()
async function myCheckToken(clientInfo,token){
// 创建uni-id实例,其上方法同uniID
const tokenRes = await uniID.createInstance({
clientInfo
}).checkToken(token)
return tokenRes
}
module.exports = {
_before: function () { // 通用预处理器
const httpInfo = this.getHttpInfo()
const clientInfo = this.getClientInfo()
const {token,body} = httpInfo.headers
if(body){
this.params = JSON.parse(body)
}
// let uid
if(token) {
// 创建uni-id实例,其上方法同uniID
this.tokenRes = myCheckToken(clientInfo,token)
// if(this.tokenRes.errCode === 0) {
// this.uid = this.tokenRes.uid
// // this.tokenRes = tokenRes
// }else{
// throw{
// // errCode: tokenRes.errCode,
// errCode: 4004,
// errMsg: 'token无效,请先登录'
// }
// }
}else{
throw{
errCode: 404,
errMsg: '请先登录'
}
}
},
test: function() {
const uid = this.tokenRes.uid //这里取的uid值为空
return this.tokenRes
},
_after(error, result) {
if(error) {
return error
}
return result
}
}
DCloud_uniCloud_WYQ
目前没有配置项,要实现这个只能去改uni-id源码
2023-12-23 14:29
随便取个昵称 (作者)
回复 DCloud_uniCloud_WYQ: 多谢答复
2023-12-23 16:45