Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

55 enable account closure #68

Merged
merged 12 commits into from
Nov 6, 2024
Merged

Conversation

jcreek
Copy link
Owner

@jcreek jcreek commented Nov 2, 2024

Summary by CodeRabbit

  • New Features

    • Introduced account deletion functionality, allowing users to request account deletion and receive confirmation emails.
    • Added new environment variables for Brevo API integration.
    • Updated documentation for database setup with new commands for applying migrations.
  • Bug Fixes

    • Improved error handling for account deletion processes.
  • Chores

    • Added a new dependency for Brevo API support.
  • Refactor

    • Enhanced the database schema to accommodate account deletion requests.

Copy link
Contributor

coderabbitai bot commented Nov 2, 2024

Warning

Rate limit exceeded

@jcreek has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 9 minutes and 43 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 1250261 and a8c7021.

Walkthrough

The changes in this pull request introduce several new features and updates across multiple files. Key additions include new environment variables related to the Brevo API, enhancements to the database setup documentation, and the introduction of a new dependency for email functionalities. Additionally, a new table for account deletion requests is created in the database schema, along with associated utility functions for handling account deletion. The application now supports account deletion via both backend logic and user interface updates.

Changes

File Change Summary
.env.example Added variables: VITE_BREVO_API_KEY, VITE_BREVO_SENDER_EMAIL, VITE_BREVO_SENDER_NAME.
docs/database-setup.md Updated with commands: npx supabase migration up, npx supabase db push.
package.json Added dependency: "@getbrevo/brevo": "^2.2.0" in dependencies.
src/lib/types/supabase.d.ts Added new table definition: account_deletion_requests with fields for deletion requests.
src/lib/utils/brevo/email.ts Introduced sendEmail function for sending emails using Brevo API.
src/lib/utils/supabase/admin.ts Added functions: requestAccountDeletion and deleteAccount for managing account deletions.
src/routes/account/+page.server.ts Introduced delete action for account deletion, minor updates to update action formatting.
src/routes/account/+page.svelte Added handleAccountDeletion function and form for account deletion.
src/routes/api/delete-account/+server.ts Added GET request handler for account deletion using a token.
src/routes/api/somebackendfunction/+server.ts Removed API route for data retrieval.
supabase/migrations/20241029193900_account_deletion.sql Created account_deletion_requests table and updated foreign key constraints for referential integrity.

Poem

🐰 In the garden of code, changes bloom bright,
New paths for deletion, a user’s delight.
With emails that flutter, like wings in the air,
Account requests handled with utmost care.
So hop on this journey, let’s celebrate cheer,
For each little change brings us all near! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

netlify bot commented Nov 2, 2024

Deploy Preview for sveltekitsaasboilerplate failed.

Name Link
🔨 Latest commit a8c7021
🔍 Latest deploy log https://app.netlify.com/sites/sveltekitsaasboilerplate/deploys/672baf8726dd0d000826ec72

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: 16

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between b83b02f and 464f365.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (11)
  • .env.example (1 hunks)
  • docs/database-setup.md (1 hunks)
  • package.json (1 hunks)
  • src/lib/types/supabase.d.ts (1 hunks)
  • src/lib/utils/brevo/email.ts (1 hunks)
  • src/lib/utils/supabase/admin.ts (3 hunks)
  • src/routes/account/+page.server.ts (3 hunks)
  • src/routes/account/+page.svelte (2 hunks)
  • src/routes/api/delete-account/+server.ts (1 hunks)
  • src/routes/api/somebackendfunction/+server.ts (0 hunks)
  • supabase/migrations/20241029193900_account_deletion.sql (1 hunks)
💤 Files with no reviewable changes (1)
  • src/routes/api/somebackendfunction/+server.ts
🧰 Additional context used
🪛 Biome
src/lib/utils/brevo/email.ts

[error] 23-23: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)

src/routes/account/+page.server.ts

[error] 26-26: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)

🔇 Additional comments (14)
.env.example (1)

7-9: LGTM! The new Brevo environment variables are properly structured.

The implementation follows good security practices with empty API key and safe default values.

src/routes/api/delete-account/+server.ts (1)

1-2: LGTM! Clean and focused imports.

The imports are well-structured and follow SvelteKit conventions.

src/lib/utils/brevo/email.ts (2)

1-6: LGTM! Secure handling of sensitive configuration.

The use of private environment variables for sensitive API configuration is a good security practice.


31-31: LGTM! Clean export statement.

The named export follows TypeScript best practices.

src/routes/account/+page.server.ts (3)

3-3: LGTM! Import statement is properly structured.


41-57: LGTM! Formatting changes improve readability.

The object structure is now more consistent with the codebase style.


22-31: 🧹 Nitpick (assertive)

Consider data cleanup implications

Whilst the account deletion request is handled, ensure there's a comprehensive cleanup strategy for:

  • User-generated content
  • Related database records
  • Authentication tokens
  • External service associations

This might warrant a background job or staged deletion process.

Let's check for potential user-related tables:

✅ Verification successful

Let me check the implementation of the account deletion request to ensure it handles these dependencies properly.


Let me check for the actual deletion implementation since we only see the request part.


Account deletion implementation is properly structured

The current implementation demonstrates a well-thought-out approach to account deletion:

  • Uses a two-step verification process with email confirmation
  • Leverages proper database constraints:
    • CASCADE deletion for critical user data (customers, user_credits)
    • SET NULL for historical records (subscriptions, purchases, credit_transactions)
  • Implements deletion through Supabase Auth admin API, which triggers the cascade/nullify constraints

The architecture appropriately handles data cleanup across all identified user-related tables whilst maintaining necessary transaction records for audit purposes.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for table definitions that might reference user data
rg -g "*.sql" "REFERENCES.*users.*id"

Length of output: 1178


Script:

#!/bin/bash
# Search for the account deletion implementation
rg -g "*.ts" -A 10 "requestAccountDeletion"

Length of output: 2361


Script:

#!/bin/bash
# Search for the actual deletion implementation
rg -g "*.ts" -A 15 "deleteAccount"

Length of output: 2370

🧰 Tools
🪛 Biome

[error] 26-26: Forbidden non-null assertion.

(lint/style/noNonNullAssertion)

package.json (2)

50-50: Verify TypeScript support for @getbrevo/brevo

The addition of Brevo for transactional emails is appropriate. However, since this is a TypeScript project, please verify that the package provides proper type definitions. If types aren't bundled, consider adding @types/getbrevo__brevo if available.

#!/bin/bash
# Check if the package includes type definitions
npm info @getbrevo/brevo types

# Search for any community-maintained type definitions
npm search @types/getbrevo

50-50: 🧹 Nitpick (assertive)

Implement email security best practices

When implementing the Brevo email service, ensure:

  1. All email templates are properly sanitised
  2. Rate limiting is implemented for account deletion requests
  3. Email verification links include secure, time-limited tokens
  4. Environment variables are properly validated at startup
supabase/migrations/20241029193900_account_deletion.sql (2)

13-46: The cascade deletion strategy looks appropriate

The mix of CASCADE and SET NULL behaviours is well-thought-out:

  • CASCADE for user-specific data that shouldn't exist without the user
  • SET NULL for historical records that should be retained for auditing

Let's verify there are no circular dependencies:

✅ Verification successful

Foreign key constraints are correctly structured without circular dependencies

The verification confirms that:

  • All foreign keys point only to auth.users or within the application schema
  • No circular references exist between tables
  • The cascade/null deletion strategy is properly implemented:
    • CASCADE for core user data (customers, users, user_credits, account_deletion_requests)
    • SET NULL for transactional history (subscriptions, purchases, credit_transactions)
  • Additional relationships to products and prices tables are independent of the user deletion flow
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any additional foreign key references to these tables
rg -t sql "FOREIGN KEY.*REFERENCES (customers|subscriptions|purchases|user_credits|credit_transactions|users)"

Length of output: 112


Script:

#!/bin/bash
# Let's try a more comprehensive search for foreign key constraints
rg -i "foreign key.*references" supabase/migrations/

Length of output: 1193


Script:

#!/bin/bash
# Also search for table definitions to understand the schema better
rg -i "create table" supabase/migrations/

Length of output: 793


Script:

#!/bin/bash
# Check for any potential circular references in the schema
fd -e sql . supabase/migrations/ -x cat {} \; | grep -i "references\|foreign key"

Length of output: 1435


7-11: 🧹 Nitpick (assertive)

Consider implementing request rate limiting

The RLS policies correctly restrict access to own records. However, there's no limit on how many deletion requests a user can create. This could potentially be abused.

Let's check if there are any existing rate limiting implementations in the codebase:

Consider adding a trigger or check constraint to prevent multiple active requests from the same user within a specific timeframe.

src/lib/types/supabase.d.ts (1)

37-62: Well-structured table definition with proper relationships

The account_deletion_requests table is well-defined with:

  • Clear field definitions
  • Proper one-to-one relationship with the users table
  • Appropriate optional/required field specifications for Insert and Update operations
src/lib/utils/supabase/admin.ts (2)

7-7: LGTM: Email utility import added correctly

The import of the sendEmail function is properly added to support the new account deletion confirmation feature.


547-549: LGTM: Export statement properly updated

The new functions are correctly added to the exports.

.env.example Outdated Show resolved Hide resolved
src/routes/api/delete-account/+server.ts Show resolved Hide resolved
src/lib/utils/brevo/email.ts Outdated Show resolved Hide resolved
src/lib/utils/brevo/email.ts Outdated Show resolved Hide resolved
src/lib/utils/brevo/email.ts Show resolved Hide resolved
docs/database-setup.md Show resolved Hide resolved
src/lib/types/supabase.d.ts Show resolved Hide resolved
src/lib/types/supabase.d.ts Show resolved Hide resolved
src/lib/utils/supabase/admin.ts Show resolved Hide resolved
src/lib/utils/supabase/admin.ts Show resolved Hide resolved
jcreek and others added 3 commits November 2, 2024 15:18
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@jcreek
Copy link
Owner Author

jcreek commented Nov 6, 2024

@OllyNicholass there are only three coderabbit threads here that need your review, the rest have been actioned or had tickets created for them :)

@OllyNicholass OllyNicholass merged commit 19f9b07 into master Nov 6, 2024
1 of 5 checks passed
@OllyNicholass OllyNicholass deleted the 55-enable-account-closure branch November 6, 2024 20:51
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