如何通知所有者数据已使用 Angular 2 Firebase 插入到 Firebase 中



我有一个Firebase项目和新用户,数据也会实时添加到数据库中。 我想在数据库发生任何更改或添加新用户时收到通知。

我们如何在 角度 .

我尝试谷歌搜索但找不到任何内容,我只是想要一封来自 firebase 的邮件给我,说数据已更改或用户已添加。

多谢

这是 Cloud Functions for Firebase 的一个很好的用例。

您可以编写在将数据添加到数据库以及首次对新用户进行身份验证时触发的函数。 以下是一些资源,可帮助您了解更多信息:

适用于 Firebase 的云函数使用指南

适用于 Firebase 示例的云函数

Firebase 云函数入门 - Firecasts

具有适用于 Firebase 的云函数的数据库触发器 - Firecasts

使用适用于 Firebase 的云函数进行身份验证触发器 - Firecats

适用于 Firebase 的云函数示例特别有用,因为它们包括如何使用 Nodemailer 发送电子邮件。

Taking Jen's answer a bit more forward .
const functions = require('firebase-functions');
const nodemailer = require('nodemailer');
// Configure the email transport using the default SMTP transport and a GMail account.
// For Gmail, enable these:
// 1. https://www.google.com/settings/security/lesssecureapps
// 2. https://accounts.google.com/DisplayUnlockCaptcha
// For other types of transports such as Sendgrid see https://nodemailer.com/transports/
// TODO: Configure the `gmail.email` and `gmail.password` Google Cloud environment variables.
const gmailEmail = encodeURIComponent(functions.config().gmail.email);
const gmailPassword = encodeURIComponent(functions.config().gmail.password);
const mailTransport = nodemailer.createTransport(
`smtps://${gmailEmail}:${gmailPassword}@smtp.gmail.com`);
// Your company name to include in the emails
// TODO: Change this to your app or company name to customize the email sent.
const APP_NAME = 'Cloud Storage for Firebase quickstart';
// [START sendWelcomeEmail]
/**
* Sends a welcome email to new user.
*/
// [START onCreateTrigger]
exports.sendWelcomeEmail = functions.auth.user().onCreate(event => {
// [END onCreateTrigger]
// [START eventAttributes]
const user = event.data; // The Firebase user.
const email = user.email; // The email of the user.
const displayName = user.displayName; // The display name of the user.
// [END eventAttributes]
return sendWelcomeEmail(email, displayName);
});
// [END sendWelcomeEmail]

// Sends a welcome email to the given user.
function sendWelcomeEmail(email, displayName) {
const mailOptions = {
from: `${APP_NAME} <noreply@firebase.com>`,
to: email
};
// The user subscribed to the newsletter.
mailOptions.subject = `Welcome to ${APP_NAME}!`;
mailOptions.text = `Hey ${displayName || ''}! Welcome to ${APP_NAME}. I hope you will enjoy our service.`;
return mailTransport.sendMail(mailOptions).then(() => {
console.log('New welcome email sent to:', email);
});
}

有关更多信息,请查看此 Firebase

最新更新