我用foreignKey把user表关联到了订单表,订单可以正常提交到云数据库,userid自动也是自动关联过来,但是订单返回值却显示提交失败,显示{"code":-1,"message":"提交订单失败","data":"未能获取当前用户信息:当前用户为匿名身份"},console.log(event, context)打印结果,难道还要把登录信息也提交上去吗,那关联表意义在哪里?
{
"DEVICEID": undefined,
"uniIdToken": undefined,
"APPID": undefined,
"PLATFORM": undefined,
"OS": undefined,
"LOCALE": undefined,
"secretType": "none",
"SOURCE": "client",
"CLIENTIP": "127.0.0.1",
"CLIENTUA": "HBuilderX",
"SPACEINFO": {
"provider": "aliyun",
"spaceId": "mp-7b2d1a86-a8c2。。。。。。。。。。",
"useOldSpaceId": false
},
"FUNCTION_NAME": "submission",
"requestId": "1aa5c659-f309-48aa-。。。。。。。。",
"FUNCTION_TYPE": "cloudfunction"
}
订单表中关联的userid
"userid": {
"bsonType": "string",
"description": "用户ID, 参考`uni-id-users` 表",
"foreignKey": "uni-id-users._id",
"defaultValue": {
"$env": "uid"
}
},
云函数
'use strict';
exports.main = async (event, context) => {
console.log(event, context)
//uniCloud.databaseForJQL方法,传入客户端信息,就可以得到一个JQL数据库操作对象。
const dbJQL = uniCloud.databaseForJQL({
event,
context
})
try {
//collection前面加dbJQL
const result = await dbJQL.collection('opendb-mall-goods').add({
name: event.name,
category: event.category,
priceType: event.priceType,
totalPrice: event.totalPrice,
})
console.log('result:', result)
return {
code: 0,
message: '提交订单成功',
data: result.data,
}
} catch (err) {
return {
code: -1,
message: '提交订单失败',
data: err.message,
}
}
}
卖火柴的咖啡猫 (作者)
前端吗?当然登录了的,用的uni-id插件,前端传给云函数的是userInfo _id,也就是user_id,是正常的
前端 const userInfo = uni.getStorageSync('uni-id-pages-userInfo')
云函数接收参数
[本地调试]{"userid":"649a56e8e1a35c1。。。。","name":"家具","category":"安装",...} {"PLATFORM":"mp-weixin","OS":"ios","APPID":"UNI10F1650",...}
2023-07-25 14:35
卖火柴的咖啡猫 (作者)
云端函数uniIdToken: undefined,,
本地云函数 "uniIdToken":"eyJhbGciOiJIUzI1N uniIdToken正常
感觉好奇怪,同一个函数为啥不一样结果
2023-07-25 14:52
DCloud_uniCloud_WYQ
回复 1***@qq.com: 看下网络请求里面有没有uniIdToken
2023-07-25 17:16