Skip to content

Conversation

@Inglan
Copy link
Member

@Inglan Inglan commented Dec 10, 2025

Summary by CodeRabbit

  • New Features
    • Automatic cleanup of backups associated with deleted user accounts for improved data management.

✏️ Tip: You can customize this high-level summary in your review settings.

@vercel
Copy link

vercel bot commented Dec 10, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
edutools Ready Ready Preview Comment Dec 10, 2025 4:18am

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 10, 2025

Walkthrough

The convex/auth.ts file was expanded to integrate authentication triggers. Changes include importing AuthFunctions from better-auth, wiring authFunctions into the authComponent, and adding a user deletion trigger that removes associated backup documents. The triggers API is exported for external use.

Changes

Cohort / File(s) Change Summary
Authentication Triggers Setup
convex/auth.ts
Added import of AuthFunctions from "@convex-dev/better-auth" and internal API reference. Introduced authFunctions bound to internal.auth and configured it within authComponent. Implemented user deletion trigger to cascade-delete associated "backups" documents. Exported triggers API (onCreate, onDelete, onUpdate) from authComponent.triggersApi().

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify the user deletion trigger correctly targets and deletes backups documents by userId
  • Confirm authFunctions binding to internal.auth is properly initialized
  • Validate that the exported triggers API matches expected function signatures

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'add backup deletion on user delete' accurately describes the main change: adding a user deletion trigger that deletes associated backup documents when a user is deleted.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch main

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Inglan Inglan changed the title add backup deletion add backup deletion on user delete Dec 10, 2025
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Dec 10, 2025

Deploying edutools-testing with  Cloudflare Pages  Cloudflare Pages

Latest commit: 42a5d74
Status:🚫  Build failed.

View logs

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0e057ea and 42a5d74.

📒 Files selected for processing (1)
  • convex/auth.ts (4 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.cursor/rules/posthog-integration.mdc)

**/*.{ts,tsx,js,jsx}: If using TypeScript, use an enum to store flag names. If using JavaScript, store flag names as strings to an object declared as a constant, to simulate an enum. Use a consistent naming convention for this storage. enum/const object members should be written UPPERCASE_WITH_UNDERSCORE.
Gate flag-dependent code on a check that verifies the flag's values are valid and expected.
If a custom property for a person or event is at any point referenced in two or more files or two or more callsites in the same file, use an enum or const object as defined for feature flags, with enum/const object members written UPPERCASE_WITH_UNDERSCORE.

Files:

  • convex/auth.ts
**/*.*

⚙️ CodeRabbit configuration file

**/*.*: Do not correct spelling errors or grammar mistakes.

Files:

  • convex/auth.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (3)
convex/auth.ts (3)

1-7: LGTM!

The import additions are correct and necessary for the new trigger functionality.


17-18: LGTM!

The authFunctions binding and integration into the authComponent configuration is correct.

Also applies to: 27-27


139-139: LGTM!

The triggers API export is correct and provides the necessary public interface.

Comment on lines +30 to +42
onDelete: async (ctx, doc) => {
if (!doc?.userId) {
return;
}

const backups = await ctx.db
.query("backups")
.withIndex("by_user", (q) => q.eq("userId", doc.userId as string))
.collect();
for (const backup of backups) {
await ctx.db.delete(backup._id);
}
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Add error handling and consider logging for the deletion loop.

The deletion loop lacks error handling, which could result in partial cleanup if any deletion fails. Additionally, there's no observability into how many backups were deleted or if any failures occurred.

Apply this diff to add error handling and logging:

 onDelete: async (ctx, doc) => {
   if (!doc?.userId) {
     return;
   }

   const backups = await ctx.db
     .query("backups")
     .withIndex("by_user", (q) => q.eq("userId", doc.userId as string))
     .collect();
+  
+  let deletedCount = 0;
+  let failedCount = 0;
+  
   for (const backup of backups) {
-    await ctx.db.delete(backup._id);
+    try {
+      await ctx.db.delete(backup._id);
+      deletedCount++;
+    } catch (error) {
+      console.error(`Failed to delete backup ${backup._id}:`, error);
+      failedCount++;
+    }
   }
+  
+  console.log(`User ${doc.userId} deleted: ${deletedCount} backups removed, ${failedCount} failed`);
 },
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
onDelete: async (ctx, doc) => {
if (!doc?.userId) {
return;
}
const backups = await ctx.db
.query("backups")
.withIndex("by_user", (q) => q.eq("userId", doc.userId as string))
.collect();
for (const backup of backups) {
await ctx.db.delete(backup._id);
}
},
onDelete: async (ctx, doc) => {
if (!doc?.userId) {
return;
}
const backups = await ctx.db
.query("backups")
.withIndex("by_user", (q) => q.eq("userId", doc.userId as string))
.collect();
let deletedCount = 0;
let failedCount = 0;
for (const backup of backups) {
try {
await ctx.db.delete(backup._id);
deletedCount++;
} catch (error) {
console.error(`Failed to delete backup ${backup._id}:`, error);
failedCount++;
}
}
console.log(`User ${doc.userId} deleted: ${deletedCount} backups removed, ${failedCount} failed`);
},
🤖 Prompt for AI Agents
In convex/auth.ts around lines 30 to 42, the deletion loop for user backups has
no error handling or logging which can lead to partial cleanup and no
observability; wrap each ctx.db.delete call in a try/catch so one failure
doesn’t stop subsequent deletes, count successful and failed deletions, and log
a summary (and individual errors) after the loop; use the repository’s existing
logger (or console.error if none) and avoid swallowing errors silently —
optionally return or rethrow an aggregated error if the caller must know about
failures.

@Inglan Inglan merged commit e1eb116 into prod Dec 10, 2025
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants