feat: send FCM token to backend on permission grant
Some checks failed
Build frontend / build (push) Failing after 25s
Some checks failed
Build frontend / build (push) Failing after 25s
This commit is contained in:
@ -43,6 +43,28 @@ export async function requestNotificationPermission() {
|
||||
});
|
||||
|
||||
console.log("[FCM] Token:", token);
|
||||
|
||||
// Send token to backend
|
||||
if (token) {
|
||||
try {
|
||||
const authToken = localStorage.getItem("auth_token");
|
||||
if (authToken) {
|
||||
const apiBase = process.env.NEXT_PUBLIC_API_URL || "http://45.93.137.91/api";
|
||||
await fetch(`${apiBase}/Notifications/RegisterWebToken`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${authToken}`,
|
||||
},
|
||||
body: JSON.stringify({ token }),
|
||||
});
|
||||
console.log("[FCM] Token sent to backend");
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("[FCM] Failed to send token to backend:", err);
|
||||
}
|
||||
}
|
||||
|
||||
return token;
|
||||
} catch (err) {
|
||||
console.error("[FCM] Error getting token:", err);
|
||||
|
||||
Reference in New Issue
Block a user