Answer the question
In order to leave comments, you need to log in
How to authenticate the VAPID public key on the server?
The js script on the client side stores the VAPID public key as a string, but sends it to the server by passing it through the urlBase64ToUint8Array function
function urlBase64ToUint8Array(base64String) {
const padding = '='.repeat((4 - (base64String.length % 4)) % 4);
const base64 = (base64String + padding).replace(/\-/g, '+').replace(/_/g, '/');
const rawData = window.atob(base64);
const outputArray = new Uint8Array(rawData.length);
for (let i = 0; i < rawData.length; ++i) {
outputArray[i] = rawData.charCodeAt(i);
}
return outputArray;
}
Answer the question
In order to leave comments, you need to log in
The urlBase64ToUint8Array() function sends encrypted keys to a third-party server (on behalf of which notifications will be sent to the user's browser), and not to your server ( the demo code of the author of this package), you need to get these keys raw on the backend yourself (in fact - read from file). You do not need to convert the keys on the backend yourself, this is decided at the level of the vendor code.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question