push notification
fix implemented
This commit is contained in:
1 parent
0bbf2ab56f
commit
57864e00da
15 files changed
+5126
-26
No files matched your search
+25
-6
@@ -30,18 +30,37 @@ export async function subscribeToPush(
|
||||
subscription: PushSubscriptionData,
|
||||
): Promise<boolean> {
|
||||
try {
|
||||
console.log('Sending subscription to server:', {
|
||||
endpoint: subscription.endpoint,
|
||||
hasKeys: !!subscription.keys,
|
||||
});
|
||||
|
||||
const payload = {
|
||||
endpoint: subscription.endpoint,
|
||||
p256dh: subscription.keys.p256dh,
|
||||
auth: subscription.keys.auth,
|
||||
};
|
||||
|
||||
console.log('Payload:', payload);
|
||||
console.log('API URL:', `${API_BASE_URL}/push/subscribe`);
|
||||
|
||||
const response = await fetch(`${API_BASE_URL}/push/subscribe`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
endpoint: subscription.endpoint,
|
||||
p256dh: subscription.keys.p256dh,
|
||||
auth: subscription.keys.auth,
|
||||
}),
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
return response.ok;
|
||||
|
||||
console.log('Subscribe response status:', response.status);
|
||||
|
||||
if (!response.ok) {
|
||||
const errorText = await response.text();
|
||||
console.error('Subscribe failed:', errorText);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('Error subscribing to push:', error);
|
||||
return false;
|
||||
|
||||
Reference in new issue
Block a user