- 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.
28 lines
No EOL
929 B
JavaScript
28 lines
No EOL
929 B
JavaScript
#!/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)
|
||
} |