Add message notif

This commit is contained in:
MartinBraquet
2025-10-31 11:52:24 +01:00
parent fdcd4d46ac
commit 5f6722b917
2 changed files with 11 additions and 11 deletions

View File

@@ -293,6 +293,7 @@ async function sendMobileNotifications(
interface PushPayload {
title: string
body: string
url: string
data?: Record<string, string>
}
@@ -302,6 +303,9 @@ export async function sendPushToToken(token: string, payload: PushPayload) {
notification: {
title: payload.title,
body: payload.body,
data: {
url: payload.url,
},
},
data: payload.data, // optional custom key-value pairs
}

View File

@@ -12,18 +12,14 @@ export const saveSubscriptionMobile: APIHandler<'save-subscription-mobile'> = as
try {
const pg = createSupabaseDirectClient()
// Check if a subscription already exists
const exists = await pg.oneOrNone(
'select id from push_subscriptions_mobile where token = $1',
[token]
await pg.none(`
insert into push_subscriptions_mobile(token, platform, user_id)
values ($1, $2, $3)
on conflict(token) do update set platform = excluded.platform,
user_id = excluded.user_id
`,
[token, 'android', userId]
);
if (!exists) {
await pg.none(`insert into push_subscriptions_mobile(token, platform, user_id) values($1, $2, $3) `,
[token, 'android', userId]
);
}
return {success: true};
} catch (err) {
console.error('Error saving subscription', err);