fix(push): reinstalled app replaces its old subscription; devices listed and removable
MindSift CI & Docker Release / Build, Test in Container & Push (push) Failing after 2m8s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
sandrodachandClaude Opus 5.5 committed 2026-10-31 11:59:40 +01:00
1 parent f76b0f34ff
commit 5b636b66e2
9 files changed
+123 -14

No files matched your search

+7 -1
View File
@@ -148,6 +148,8 @@ func (s *Server) handlePushSubscribe(w http.ResponseWriter, r *http.Request) {
Auth string `json:"auth"`
} `json:"keys"`
Device string `json:"device"`
// The subscription this browser had before (e.g. before a reinstall): it is dead now
Replaces string `json:"replaces"`
}
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
writeError(w, http.StatusBadRequest, "Ungültige Anfrage")
@@ -165,10 +167,14 @@ func (s *Server) handlePushSubscribe(w http.ResponseWriter, r *http.Request) {
if len(device) > 120 {
device = device[:120]
}
if err := s.store.SavePushSubscription(auth.GetUserID(r.Context()), req.Endpoint, req.Keys.P256dh, req.Keys.Auth, device); err != nil {
userID := auth.GetUserID(r.Context())
if err := s.store.SavePushSubscription(userID, req.Endpoint, req.Keys.P256dh, req.Keys.Auth, device); err != nil {
writeError(w, http.StatusInternalServerError, "Gerät konnte nicht gespeichert werden")
return
}
if req.Replaces != "" && req.Replaces != req.Endpoint {
_ = s.store.DeletePushSubscription(userID, req.Replaces) // only ever one of the own devices
}
writeJSON(w, http.StatusOK, map[string]bool{"ok": true})
}