Read vapid subject from the environment

Load the contact details for push notifications from the
NUXT_VAPID_SUBJECT environment variable.
This commit is contained in:
Hornwitser 2025-05-20 00:25:28 +02:00
parent c986d939ec
commit a16921f264
2 changed files with 3 additions and 1 deletions

View file

@ -4,6 +4,7 @@ export default defineNuxtConfig({
devtools: { enabled: true },
runtimeConfig: {
cookieSecretKey: "",
vapidSubject: "",
vapidPrivateKey: "",
public: {
defaultTimezone: "Europe/Oslo",

View file

@ -14,11 +14,12 @@ function useVapidDetails(event: H3Event) {
}
const runtimeConfig = useRuntimeConfig(event);
if (!runtimeConfig.vapidSubject) throw new Error("NUXT_VAPID_SUBJECT not set.")
if (!runtimeConfig.public.vapidPublicKey) throw new Error("NUXT_PUBLIC_VAPID_PUBLIC_KEY not set.")
if (!runtimeConfig.vapidPrivateKey) throw new Error("NUXT_VAPID_PRIVATE_KEY not set.")
return cachedVapidDetails = {
subject: "mailto:webmaster@hornwitser.no",
subject: runtimeConfig.vapidSubject,
publicKey: runtimeConfig.public.vapidPublicKey,
privateKey: runtimeConfig.vapidPrivateKey,
}