Skip to content

Commit

Permalink
fix: don't allow user deletion with active subscriptions
Browse files Browse the repository at this point in the history
See: BEDS-924
  • Loading branch information
LuccaBitfly committed Jan 21, 2025
1 parent 0ed1e97 commit 0432783
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions backend/pkg/api/handlers/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -739,20 +739,34 @@ func (h *HandlerService) InternalPostLogout(w http.ResponseWriter, r *http.Reque
}

func (h *HandlerService) InternalDeleteUser(w http.ResponseWriter, r *http.Request) {
user, err := h.getUserBySession(r)
userId, err := h.GetUserIdBySession(r)
if err != nil {
handleErr(w, r, err)
return
}

// TODO allow if user has any subsciptions etc?
err = h.daService.RemoveUser(r.Context(), user.Id)
userInfo, err := h.daService.GetUserInfo(r.Context(), userId)
if err != nil {
handleErr(w, r, err)
return
}
// don't allow deletion of users with active subscriptions
if subscriptions := userInfo.Subscriptions; len(subscriptions) > 0 {
for _, subscription := range subscriptions {
if time.Unix(subscription.End, 0).After(time.Now()) {
handleErr(w, r, newConflictErr("user has active subscriptions, please cancel them first before deleting the account"))
return
}
}
}

err = h.purgeAllSessionsForUser(r.Context(), user.Id)
err = h.daService.RemoveUser(r.Context(), userId)
if err != nil {
handleErr(w, r, err)
return
}

err = h.purgeAllSessionsForUser(r.Context(), userId)
if err != nil {
handleErr(w, r, err)
return
Expand Down

0 comments on commit 0432783

Please sign in to comment.