Don't try sending web push notifs if env vars not set

This commit is contained in:
Kalle 2025-04-16 17:51:01 +03:00
parent dd9fa3ec02
commit b71b606913
2 changed files with 6 additions and 1 deletions

View File

@ -7,7 +7,7 @@ import { logger } from "../../../utils/logger";
import * as NotificationRepository from "../NotificationRepository.server";
import type { Notification } from "../notifications-types";
import { notificationLink } from "../notifications-utils";
import webPush from "./webPush.server";
import webPush, { webPushEnabled } from "./webPush.server";
/**
* Create notifications both in the database and send push notifications to users (if enabled).
@ -102,6 +102,8 @@ async function sendPushNotification({
notification: Notification;
t: TFunction<["common"], undefined>;
}) {
if (!webPushEnabled) return;
try {
await webPush.sendNotification(
subscription,

View File

@ -1,6 +1,8 @@
import webPush from "web-push";
import { logger } from "~/utils/logger";
export let webPushEnabled = false;
if (
process.env.VAPID_EMAIL &&
process.env.VITE_VAPID_PUBLIC_KEY &&
@ -11,6 +13,7 @@ if (
process.env.VITE_VAPID_PUBLIC_KEY,
process.env.VAPID_PRIVATE_KEY,
);
webPushEnabled = true;
} else {
logger.info("VAPID env vars not set, push notifications will not work");
}