Meh*_*osh 6 javascript node.js firebase firebase-authentication google-cloud-firestore
我想在触发器函数中 setCustomUserClaims 但随后出现此错误
这是我的一段代码:
exports.onCreateCompaniesByUserFunction =
functions.firestore.document('/companiesByUser/{userId}').onWrite((change, context) => {
const { userId } = context.params;
const document = change.after.exists ? change.after.data() : null;
console.log('document',document)
let owner = []
let employee = []
let editor = []
Object.keys(document).map(key => {
if (document[key] == 'affiliate' || document[key] == 'employee') {
employee.push( key )
} else if (document[key] == 'owner') {
owner.push( key )
} else if (document[key] == 'editor') {
editor.push( key )
}
});
console.log('owner',owner)
console.log('employee',employee)
console.log('editor',editor)
console.log('before the claims 2',userId)
return admin.auth().setCustomUserClaims(userId, {employee, owner, editor})
.then(() => {
console.log('claim set successfully!');
return true;
})
.catch((error) => {
console.log('in error',error);
});
});
Run Code Online (Sandbox Code Playgroud)
根据日志中显示UserId存在但没有对应的用户。
您确定使用正确的数据库配置吗?也许您忘记将连接从暂存更改为生产。您应该仔细检查您的数据库配置(通常在functions/index.js):
admin.initializeApp({
credential: YOUR_CREDENTIAL_FILE,
databaseURL: 'YOUR_DATABSE_URL',
...
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4542 次 |
| 最近记录: |