[英]Cloud functions: oncall function returns null before running chain of promises
我創建了一個雲函數來創建一個 firebase auth 用戶並將用戶的數據記錄到 firestore 中。
雲功能
const admin = require('firebase-admin');
admin.initializeApp();
exports.createUser = functions.https.onCall((data, response) => {
admin.auth().createUser({
email: data.email,
password: data.password,
displayName: data.name
}).then(user => {
return admin.firestore().collection('users').doc(user.uid).set({
email: data.email,
id: user.uid,
name: data.name,
role: data.role
});
}).then(() => {
return { status: true, message: 'User added successfully!' };
}).catch(error => {
return { status: false, message: 'Error occurred while creating the user!' };
})
})
角度 .ts 文件
export class AddUserComponent implements OnInit {
constructor(private angularFireAuth: AngularFireAuth) {}
ngOnInit(): void {
}
onSubmit(user) {
this.angularFireFunctions.httpsCallable('createUser')(user).subscribe(response => {
console.log(response);
}, error => {
console.log(error);
});
}
}
當我使用 angular/fire 在我的 angular 應用程序中調用此函數時,它返回 null。 此外,將用戶添加到 firestore 最多需要 3 分鍾。 我應該在這段代碼中修改什么?
就像在這里發回 onCall 函數的結果的 firebase 文檔中一樣,您應該返回任何異步函數。 因此,在雲函數中的admin.auth()...
之前添加return
關鍵字。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.