Skip to content

Commit ee3ab6a

Browse files
Restored saveToken function that was deleted by a lazy MLLM (and a lazy me for not double checking that they didn't truncate anything).
1 parent 7a55dde commit ee3ab6a

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

utils/notifications.utils.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ export const registerForPushNotificationsAsync = async () => {
4343

4444
console.log("Expo Push Token:", token);
4545

46+
// Save the token to the server
4647
if (token) {
47-
// This function seems to be missing from your provided file, assuming it exists elsewhere
48-
// await savePushToken(token);
48+
await savePushToken(token);
4949
}
5050

5151
return token;
@@ -129,8 +129,28 @@ export const handleBackgroundNotifications = () => {
129129
};
130130

131131
export const savePushToken = async (token: string): Promise<void> => {
132-
// Implementation from your file
133-
// ...
132+
try {
133+
const response = await fetch(
134+
"https://new.codebuilder.org/api/notifications/subscribe",
135+
{
136+
method: "POST",
137+
headers: { "Content-Type": "application/json" },
138+
body: JSON.stringify({
139+
endpoint: "https://fcm.googleapis.com/fcm/send",
140+
keys: { token },
141+
type: "fcm",
142+
}),
143+
}
144+
);
145+
146+
if (!response.ok) {
147+
throw new Error(`Error saving token: ${response.statusText}`);
148+
}
149+
150+
console.log("Push token saved to server successfully.");
151+
} catch (error) {
152+
console.error("Error saving push token to server:", error);
153+
}
134154
};
135155

136156
// Example function to trigger a local notification

0 commit comments

Comments
 (0)