getInitecode:async function(){
const db=uniCloud.databaseForJQL()
const id=await this.uniID.checkToken(this.getUniIdToken())
const res=await db.collection('uni-id-users').where('_id=="'+id.uid+'"').field('my_invite_code').get()
return res
}
在保证数据库权限和用户权限没有问题的前题下,
如上代码,会报"Error: 权限校验未通过,未能获取当前用户信息,当前用户为匿名身份,"
问题是在代码第二行,
即使你在前段登录,在本地有TOKEN,但是在云函数里使用数据库连接时,并不能自动传送本地TOKEN信息到数据库连接.
这种情况只需要在第二行改为
const db=uniCloud.databaseForJQL({clientInfo:this.getClientInfo()})
然后就不报权限错误了.
倒数第二行JQL语法里where语句中,这样是正常工作的,但是文档中的,.where('_id==$cloudEnv_uid')写法不生效,会报个本地没有schema的错.
不知道什么原因.如下所示
//const res=await db.collection('uni-id-user').where('_id==$cloudEnv_uid').field('my_invite_code').get()