I am currently working on the implementation of push notifications. To do this, the web push api requires the subscription object which contains the public as well as the private key. Additionally the subscription needs to be stored in a database for later use.
#################
#Subscription Object
#################
endpoint: { type: String, unique: true},
keys: {
p256dh: {type: String},
auth: {type: String}
},
#################
#Sending the Notification
#################
webpush.sendNotification(subscription, payload).catch(console.log);
Personally, I am not sure if I should save the private key in the database.
Is there a better approach to this? Or is it actually safe to store this information in this format?