I am currently reading on developers.google.com about push notifications.
And I've come so far as to get a push subscription object.
But I am not sure about the best way to save it.
Here is the code from google
function subscribeUserToPush() {
return getSWRegistration().then(function(registration) {
const subscribeOptions = {
userVisibleOnly: true,
applicationServerKey: urlBase64ToUint8Array('XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
};
return registration.pushManager.subscribe(subscribeOptions);
}).then(function(pushSubscription) {
console.log('Received PushSubscription: ', JSON.stringify(pushSubscription));
return pushSubscription;
});
}
I have a database, with a table of users, so should I create a new column there, and store the stringified JSON subscription object there?
Or better to create a new table for subscriptions?
For example a table like this?
user_id | endpoint | p256dh | auth
Can a user have multiple subscriptions? In that case a dedicated subscription table is preferred I think.
And about the VAPID keys, should I just put the public right into the code like above? And then store the private one somewhere safe?
Thank you.