From 4ef5c268ebb1bd21d8025e57e7275bc14bd32053 Mon Sep 17 00:00:00 2001 From: Abhishek Y <75441358+abyii@users.noreply.github.com> Date: Sat, 14 Dec 2024 20:11:57 +0530 Subject: [PATCH] docs: fixed parsing of base64String by regex, updated subscribeToPush function Change 1: At line 107, the regex code is now fixed to replace all "-" with "+", which wasn't as expected with previous code, window.atob() would throw an error saying the string is not encoded properly. The variable base64 will now have a URL safe base64String. Change 2: At line 177 and 178, the function is now updated to call the server action subscribeUser() with a serialized object instead of a PushSubscription object, as server actions can only be called with serialized objects. Thankyou. --- .../07-configuring/16-progressive-web-apps.mdx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/01-app/03-building-your-application/07-configuring/16-progressive-web-apps.mdx b/docs/01-app/03-building-your-application/07-configuring/16-progressive-web-apps.mdx index 4388fa19b80d8..ad23f73746d35 100644 --- a/docs/01-app/03-building-your-application/07-configuring/16-progressive-web-apps.mdx +++ b/docs/01-app/03-building-your-application/07-configuring/16-progressive-web-apps.mdx @@ -104,7 +104,7 @@ import { subscribeUser, unsubscribeUser, sendNotification } from './actions' function urlBase64ToUint8Array(base64String: string) { const padding = '='.repeat((4 - (base64String.length % 4)) % 4) const base64 = (base64String + padding) - .replace(/\\-/g, '+') + .replace(/-/g, '+') .replace(/_/g, '/') const rawData = window.atob(base64) @@ -174,7 +174,8 @@ function PushNotificationManager() { ), }) setSubscription(sub) - await subscribeUser(sub) + const serializedSub = JSON.parse(JSON.stringify(sub)) + await subscribeUser(serializedSub) } async function unsubscribeFromPush() {