Skip to content

Commit

Permalink
fix: fix failing push notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Prithpal-Sooriya committed Jun 14, 2024
1 parent 2aaf565 commit 2fca24c
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,21 @@ export async function listenToPushNotifications(
const unsubscribePushNotifications = onBackgroundMessage(
messaging,
async (payload: MessagePayload): Promise<void> => {
const typedPayload = payload;

// if the payload does not contain data, do nothing
try {
const notificationData: NotificationUnion = typedPayload?.data?.data
? JSON.parse(typedPayload?.data?.data)
const data = payload?.data?.data
? JSON.parse(payload?.data?.data)
: undefined;

if (!notificationData) {
// if the payload does not contain data, do nothing
if (!data) {
return;
}

const notificationData = {
...data,
type: data?.type ?? data?.data?.kind,
} as NotificationUnion;

const notification = processNotification(notificationData);
onNewNotification(notification);

Expand Down

0 comments on commit 2fca24c

Please sign in to comment.