google-cloud-firestore - 在firebase firestore云功能中获取当前用户的uid
问题描述
是否有可能在firebase firestore云功能中获取当前用户的uid。我尝试了一个示例代码,但它总是抛出一个错误;有没有办法实现这个功能?
这是我的代码:
exports.test = functions.firestore.document('test/{doc}')
.onCreate(async (snap, context) => {
const db = admin.auth();
const uid = context.auth.uid;
console.log(context.auth.uid, 'is the uid of cuurent user');
console.log(db.getUser(uid), 'is the current user');
return;
});
这段代码总是抛出错误;我不知道为什么?
TypeError: Cannot read property 'uid' of undefined
at Object.<anonymous> (/user_code/lib/index.js:291:29)
at next (native)
at /user_code/lib/index.js:7:71
at __awaiter (/user_code/lib/index.js:3:12)
at exports.test.functions.firestore.document.onCreate (/user_code/lib/index.js:289:34)
at cloudFunctionNewSignature (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:105:23)
at cloudFunction (/user_code/node_modules/firebase-functions/lib/cloud-functions.js:135:20)
at /var/tmp/worker/worker.js:769:24
at process._tickDomainCallback (internal/process/next_tick.js:135:7);
解决方案
推荐阅读
- kentico - Kentico 持续集成 - 用户登录失败
- javascript - 使用 jquery 的提示按钮
- assembly - 带有 KCPSM3 指令集的 picoblaze IDE
- excel - 在 For 循环中显示合并的单元格数据
- node.js - Nginx 访问日志条目在发生时不会为某些连接创建
- java - 计算 ArrayList 中特定类型的引用次数
- python - Python 3.7 中的 conda 和 argparse 冲突
- python-3.x - 如何将 python 的 subprocess.Popen 与单个输入 csv 和每个进程输入一行一起使用?
- google-apps-script - 用于插入另一个文档的 Google Docs 脚本
- javascript - 在浏览器中包含 babel-polyfill 会变慢