Browse Source

Debugging and ironing out the flow

web-push-permissions
Matthew Raymer 1 year ago
parent
commit
2eaa4203aa
  1. 7
      src/App.vue

7
src/App.vue

@ -267,7 +267,6 @@ import axios from "axios";
export default class App extends Vue { export default class App extends Vue {
b64 = ""; b64 = "";
mounted() { mounted() {
// Your API call logic here
axios axios
.get("https://timesafari-pwa.anomalistlabs.com/web-push/vapid") .get("https://timesafari-pwa.anomalistlabs.com/web-push/vapid")
.then((response) => { .then((response) => {
@ -372,12 +371,14 @@ export default class App extends Vue {
if ("serviceWorker" in navigator && "PushManager" in window) { if ("serviceWorker" in navigator && "PushManager" in window) {
navigator.serviceWorker.ready navigator.serviceWorker.ready
.then((registration) => { .then((registration) => {
console.log(this.b64);
const applicationServerKey = this.urlBase64ToUint8Array(this.b64); const applicationServerKey = this.urlBase64ToUint8Array(this.b64);
const options: PushSubscriptionOptions = { const options: PushSubscriptionOptions = {
userVisibleOnly: true, userVisibleOnly: true,
applicationServerKey: applicationServerKey, applicationServerKey: applicationServerKey,
}; };
console.log(options);
return registration.pushManager.subscribe(options); return registration.pushManager.subscribe(options);
}) })
@ -400,8 +401,8 @@ export default class App extends Vue {
private sendSubscriptionToServer( private sendSubscriptionToServer(
subscription: PushSubscription, subscription: PushSubscription,
): Promise<void> { ): Promise<void> {
// Simulated API call console.log(subscription);
return fetch("/api/save-subscription", { return fetch("/web-push/subscribe", {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",

Loading…
Cancel
Save