Firebase 在本地测试 auth 云功能
Firebase test auth cloud functions locally
exports.sendWelcomeEmail = functions.auth.user().onCreate((user) => {
console.log(user.uid);
console.log(user.email);
console.log(user.displayName);
});
exports.getUserInfo = functions.https.onCall(async (data, context) => {
// get array of user IDs and returns information (from Users collection)
const userIDs = data.userIDs;
const result = [];
const querySnapData = await admin.firestore().collection("Users").get();
querySnapData.forEach((ele) => {
if (userIDs.indexOf(ele.id) !== -1 && ele.id !== context.auth.uid) {
result.push(ele.data());
}
});
return { res: result };
});
我的项目中有这两个函数 - 一个是可调用函数,另一个是 auth 触发器函数。
所以在我的客户端应用程序中,我 运行
firebase.functions().useFunctionsEmulator('http://localhost:5001');
let getUserInfo = functions.httpsCallable('getUserInfo');
getUserInfo({userIDs: data}).then(res => doSomething);
并且 运行 本地云功能
firebase emulators:start
但是它说
functions[sendWelcomeEmail]: function ignored because the auth emulator does not exist or is not running.
所以在客户端App中,getUserInfo
效果很好,但无法触发onCreate
。
但是我找不到任何关于 auth emulator
的文档。
欢迎任何link/article/video或回答。
Firebase 模拟器套件目前有云 Firestore、实时数据库、云函数和云 Pub/Sub。它尚未模拟 Firebase 身份验证 API。因此,您进行的任何身份验证调用都将针对与模拟器关联的真实项目执行。
这也意味着您的 functions.auth.user().onCreate((user) => {
Cloud Function 目前不会在模拟器中触发。您必须将其部署到服务器以测试此触发器。
要了解身份验证模拟器何时可用,我建议您关注 Firebase 的 release notes, and on the main documentation page for the emulator suite that lists the supported products. You can also follow along more closely on Github, either in the commits, or in this feature request。
正如@Franek van Puffelen 上面所写的那样,它还没有完成。
能够像下面这样在本地测试身份验证功能。
function sendWelcomeEmail(user) {
console.log(user.uid);
console.log(user.email);
console.log(user.displayName);
}
exports.sendWelcomeEmail = functions.auth.user().onCreate((user) => sendWelcomeEmail(user));
firebase 最近发布了身份验证模拟器,您可以通过此处的发行说明查看:https://firebase.google.com/support/releases#october_26_2020, and further guide here: https://firebase.google.com/docs/emulator-suite/connect_auth
exports.sendWelcomeEmail = functions.auth.user().onCreate((user) => {
console.log(user.uid);
console.log(user.email);
console.log(user.displayName);
});
exports.getUserInfo = functions.https.onCall(async (data, context) => {
// get array of user IDs and returns information (from Users collection)
const userIDs = data.userIDs;
const result = [];
const querySnapData = await admin.firestore().collection("Users").get();
querySnapData.forEach((ele) => {
if (userIDs.indexOf(ele.id) !== -1 && ele.id !== context.auth.uid) {
result.push(ele.data());
}
});
return { res: result };
});
我的项目中有这两个函数 - 一个是可调用函数,另一个是 auth 触发器函数。
所以在我的客户端应用程序中,我 运行
firebase.functions().useFunctionsEmulator('http://localhost:5001');
let getUserInfo = functions.httpsCallable('getUserInfo');
getUserInfo({userIDs: data}).then(res => doSomething);
并且 运行 本地云功能
firebase emulators:start
但是它说
functions[sendWelcomeEmail]: function ignored because the auth emulator does not exist or is not running.
所以在客户端App中,getUserInfo
效果很好,但无法触发onCreate
。
但是我找不到任何关于 auth emulator
的文档。
欢迎任何link/article/video或回答。
Firebase 模拟器套件目前有云 Firestore、实时数据库、云函数和云 Pub/Sub。它尚未模拟 Firebase 身份验证 API。因此,您进行的任何身份验证调用都将针对与模拟器关联的真实项目执行。
这也意味着您的 functions.auth.user().onCreate((user) => {
Cloud Function 目前不会在模拟器中触发。您必须将其部署到服务器以测试此触发器。
要了解身份验证模拟器何时可用,我建议您关注 Firebase 的 release notes, and on the main documentation page for the emulator suite that lists the supported products. You can also follow along more closely on Github, either in the commits, or in this feature request。
正如@Franek van Puffelen 上面所写的那样,它还没有完成。
能够像下面这样在本地测试身份验证功能。
function sendWelcomeEmail(user) {
console.log(user.uid);
console.log(user.email);
console.log(user.displayName);
}
exports.sendWelcomeEmail = functions.auth.user().onCreate((user) => sendWelcomeEmail(user));
firebase 最近发布了身份验证模拟器,您可以通过此处的发行说明查看:https://firebase.google.com/support/releases#october_26_2020, and further guide here: https://firebase.google.com/docs/emulator-suite/connect_auth