我一直在尝试使用示例验证码来实现利用用户身份验证信息“模拟”用户并代表用户执行写操作的示例:https://firebase.google.com/docs/functions/database-events
我无法获得过去的权限被拒绝错误。我已经尝试实现一些帖子中所示的adminRef,但无济于事。任何帮助将不胜感激
exports.impersonateMakeUpperCase = functions.database.ref('/messages/{pushId}/original')
.onCreate((snap, context) => {
const appOptions = JSON.parse(process.env.FIREBASE_CONFIG);
appOptions.databaseAuthVariableOverride = context.auth;
const app = admin.initializeApp(appOptions, 'app');
const uppercase = snap.val().toUpperCase();
const ref = snap.ref.parent.child('uppercase');
const deleteApp = () => app.delete().catch(() => null);
return app.database().ref(ref).set(uppercase).then(res => {
// Deleting the app is necessary for preventing concurrency leaks
return deleteApp().then(() => res);
}).catch(err => {
return deleteApp().then(() => Promise.reject(err));
});
});
编辑:尽管我从云功能日志中使用firebase.auth()。signInWithEmailAndPassword通过电子邮件/密码登录的测试客户端应用触发了此数据库更改,但我仍将authType视为未经身份验证的,我要注销auth和authtype:const authVar = context.auth; const authType = context.authType;分别显示NULL和UNAUTHENTICATED。
编辑:如果我在通过firebase.auth()。signInWithCustomToken()进行身份验证之后从客户端触发db事件,情况也是如此
Firebase onCreate trigger: can't get authType other than UNAUTHENTICATED