mirror of
https://github.com/fromchat-messenger/web.git
synced 2026-09-23 03:25:07 +03:00
Redesign settings from scratch
This commit is contained in:
@@ -22,4 +22,15 @@ export async function changePassword(
|
||||
if (!res.ok) throw new Error("Failed to change password");
|
||||
}
|
||||
|
||||
export async function deleteAccount(token: string): Promise<void> {
|
||||
const res = await fetch(`${API_BASE_URL}/account/delete`, {
|
||||
method: "POST",
|
||||
headers: getAuthHeaders(token)
|
||||
});
|
||||
if (!res.ok) {
|
||||
const error = await res.json().catch(() => ({ detail: "Failed to delete account" }));
|
||||
throw new Error(error.detail || "Failed to delete account");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -183,6 +183,21 @@ export async function subscribe(token: string): Promise<boolean> {
|
||||
return true;
|
||||
}
|
||||
|
||||
// If subscription doesn't exist, try to get it from the push manager or create a new one
|
||||
if (!subscription && registration) {
|
||||
try {
|
||||
// Try to get existing subscription first
|
||||
subscription = await registration.pushManager.getSubscription();
|
||||
// If no existing subscription, create a new one
|
||||
if (!subscription) {
|
||||
subscription = await subscribeToWebPush();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Failed to get or create subscription:", error);
|
||||
subscription = await subscribeToWebPush();
|
||||
}
|
||||
}
|
||||
|
||||
return await sendSubscriptionToServer(token);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user