web-app/generate-vapid-keys.js
padreug 8a9ffc5918 feat: Implement secure VAPID key generation for push notifications
- Replace random key generation with the web-push library for generating cryptographically secure VAPID keys.
- Update console output to guide users on adding keys to their environment configuration.
- Enhance error handling for VAPID key generation issues.
- Add web-push dependency to package.json and package-lock.json for proper functionality.
2025-07-12 18:10:33 +02:00

28 lines
No EOL
929 B
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env node
// Proper VAPID key generator using web-push library
import webpush from 'web-push'
console.log('🔑 VAPID Key Generator for Push Notifications')
console.log('')
try {
// Generate proper VAPID keys using web-push
const vapidKeys = webpush.generateVAPIDKeys()
console.log('📋 Add these to your .env file:')
console.log('')
console.log(`VITE_VAPID_PUBLIC_KEY=${vapidKeys.publicKey}`)
console.log(`VITE_PUSH_NOTIFICATIONS_ENABLED=true`)
console.log('')
console.log('🔐 Private key (keep secure, for backend only):')
console.log(`VAPID_PRIVATE_KEY=${vapidKeys.privateKey}`)
console.log('')
console.log('✅ Once added, restart your dev server to apply the changes.')
console.log('')
console.log(' These are cryptographically secure VAPID keys suitable for production.')
} catch (error) {
console.error('❌ Error generating VAPID keys:', error)
process.exit(1)
}