fix(auth): wipe user-owned content before Better-Auth deletes the user #51
Loading…
Reference in a new issue
No description provided.
Delete branch "audit/legal-compliance"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
DataWipe.wipeUserDatainto Better-Auth'suser.deleteUser.beforeDeletehook so account deletion succeeds even when the user owns shoots/frames/personal globals.Why
Audit of the legal pages found that the privacy policy promised "if you delete your account, all associated data is permanently deleted" but the actual delete-account button (
authClient.deleteUser->/api/auth/delete-user) was failing withupdate or delete on table "user" violates foreign key constraint "frame_createdBy_user_id_fk". The user.id FKs on shoot/frame/folder/camera/lens/filter/weather/iso/film/film_format/film do not cascade, and there was no hook wiping owned content first.DataWipe.wipeUserDataalready existed (used by the import/export "wipe + reimport" flow); this PR reuses it from auth.ts via a plainnew DataWipe()since the hook fires outside the Nest DI container.Test plan
test/int/auth-delete-user.int-spec.ts- RED before fix (FK violation, 500), GREEN after.pnpm test:int- 101/101 passing.pnpm test- 63/63 passing.pnpm build- clean.pnpm lint- clean./accountin the front; expect 200 and no orphan rows.