start adding payment
This commit is contained in:
+24
-2
@@ -18,7 +18,9 @@ const WELCOME_EMAIL_SUBJECT = "Bienvenue sur MusicLand";
|
||||
exports.testWelcomMail = onRequest(async (req, res) => {
|
||||
if (req.method !== "GET") {
|
||||
res.set("Allow", "GET");
|
||||
return res.status(405).json({ success: false, error: "Method not allowed" });
|
||||
return res
|
||||
.status(405)
|
||||
.json({ success: false, error: "Method not allowed" });
|
||||
}
|
||||
try {
|
||||
const targetEmail = req.query.email || "tdtomthomas@gmail.com";
|
||||
@@ -48,7 +50,27 @@ exports.testWelcomMail = onRequest(async (req, res) => {
|
||||
|
||||
exports.onUserCreated = onDocumentCreated("users/{userID}", async (event) => {
|
||||
try {
|
||||
const { email = "", firstName = "", lastName = "" } = event?.data?.data();
|
||||
const {
|
||||
email = "",
|
||||
firstName = "",
|
||||
lastName = "",
|
||||
} = event?.data?.data() || {};
|
||||
|
||||
try {
|
||||
await event.data.ref.set(
|
||||
{
|
||||
coins: admin.firestore.FieldValue.increment(10),
|
||||
coinWelcomeGrantedAt: admin.firestore.FieldValue.serverTimestamp(),
|
||||
},
|
||||
{ merge: true },
|
||||
);
|
||||
} catch (coinError) {
|
||||
console.warn(
|
||||
"[users-onUserCreated] Unable to grant welcome coins",
|
||||
event?.params?.userID,
|
||||
coinError?.message || coinError,
|
||||
);
|
||||
}
|
||||
if (email) {
|
||||
if (!resendClient) {
|
||||
console.warn("Resend API key not configured; skipping welcome email.");
|
||||
|
||||
Reference in New Issue
Block a user