From 43783a07ca2d9793c3d9b064c85487fcc2a57cf4 Mon Sep 17 00:00:00 2001 From: wusumac <736139669@qq.com> Date: Sun, 2 Aug 2026 22:57:13 +0800 Subject: [PATCH] fix(web): record VAPID key only after hub registration succeeds --- web/src/hooks/usePushNotifications.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/web/src/hooks/usePushNotifications.ts b/web/src/hooks/usePushNotifications.ts index 4ba03d07..f6b8f6a3 100644 --- a/web/src/hooks/usePushNotifications.ts +++ b/web/src/hooks/usePushNotifications.ts @@ -143,7 +143,6 @@ export function usePushNotifications(api: ApiClient | null) { applicationServerKey }) } - writeStoredVapidKey(publicKey) const json = subscription.toJSON() const keys = json.keys @@ -158,6 +157,11 @@ export function usePushNotifications(api: ApiClient | null) { auth: keys.auth } }) + // Only record the key after the hub registration succeeded. A + // failed registration must leave the previous key in place so the + // next load retries the replacement instead of reusing a + // subscription the hub never learned about. + writeStoredVapidKey(publicKey) setIsSubscribed(true) return true } catch (error) {