我正在尝试从云函数的不同节点中创建以下两个文档,但不确定如何返回这两个文档。
// Listen to .onCreate trigger
exports.createUserAndProfile = functions.auth.user().onCreate((user) => {
// Create a new user (only the user themselves can access this)
const newUser = admin.firestore().doc(`/users/${user.uid}`).set({
announcements: [],
email: user.email,
onboardingSteps: ["setName", "syncStuff"],
});
// Create the user's public profile (any user can access this)
const newPublicProfile = admin.firestore().doc(`/profiles/${user.uid}`).set({
firstName: null,
lastName: null,
preferredName: null,
});
return newUser;
});
如果您希望在终止云函数之前完成两次写入,您可以在Promise.all()
调用中返回它们:
return Promise.all(newUser, newPublicProfile);
另请参阅Promise.all
的MDN文档。