Skip to content

Account settings + delete account#104

Open
aloewright wants to merge 1 commit into
mainfrom
conductor/alo-132-account-settings-delete-account
Open

Account settings + delete account#104
aloewright wants to merge 1 commit into
mainfrom
conductor/alo-132-account-settings-delete-account

Conversation

@aloewright
Copy link
Copy Markdown
Owner

Closes ALO-132.

Email/password change and 30-day grace-period delete already shipped on main (migrations 0012, account.ts routes, AccountSettings page). This PR adds the remaining piece called out in the ticket: manage notifications.

Summary

  • New migration 0019_notification_prefs.sql adds notify_product_emails and notify_marketing_emails to user (default 1).
  • GET /api/account now returns notifications: { productEmails, marketingEmails }.
  • New PUT /api/account/notifications validates with zod, persists, and mirrors marketing opt-out to the Resend audience (unsubscribed flag) when Resend is configured.
  • Account settings page renders a Notifications section with two checkboxes; updates are optimistic with rollback on failure.
  • Tests cover the new endpoint (success + 400 invalid payload) and the test fakes are extended for the new columns.

Test plan

  • npm test — 44 files, 493 tests passing
  • npm run lint — clean (incl. AI-Gateway guard)
  • npm run type-check — clean

Adds product/marketing email toggles to the account settings page,
backed by a new GET-augmented `/api/account` payload and a
`PUT /api/account/notifications` endpoint. Marketing opt-out mirrors
to the Resend audience so bulk sends honor the preference without
re-implementing list segmentation.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 8, 2026 14:49
@aloewright aloewright added the conductor Conductor-managed PR label May 8, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 8, 2026

Warning

Rate limit exceeded

@aloewright has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 55 minutes and 26 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ 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.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4d5905fe-8ac9-4b05-a69c-78d81ed7dba2

📥 Commits

Reviewing files that changed from the base of the PR and between 4d3c13f and 9872859.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (4)
  • src/db/migrations/0019_notification_prefs.sql
  • src/frontend/pages/AccountSettings.tsx
  • src/workers/account.test.ts
  • src/workers/account.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch conductor/alo-132-account-settings-delete-account

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.

@ecc-tools
Copy link
Copy Markdown
Contributor

ecc-tools Bot commented May 8, 2026

ECC bundle files are already tracked in this repository. Skipping generation of another bundle PR.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request implements per-user notification preferences for product and marketing emails, including a database migration, a new API endpoint, and frontend UI updates. The implementation also mirrors marketing opt-out status to Resend. Feedback was provided to improve data consistency by using the RETURNING clause in the SQL update and to enhance performance by offloading the Resend API call to a background task using waitUntil.

Comment thread src/workers/account.ts
Comment on lines +92 to +103
await c.env.DB.prepare(
`UPDATE user
SET notify_product_emails = ?, notify_marketing_emails = ?, updatedAt = ?
WHERE id = ?`,
)
.bind(
parsed.data.productEmails ? 1 : 0,
parsed.data.marketingEmails ? 1 : 0,
Date.now(),
user.id,
)
.run();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Using RETURNING email in the UPDATE statement allows you to retrieve the most up-to-date email address directly from the database. This ensures that the subsequent Resend mirroring uses the correct email, even if it was recently changed and the session data in the request context is stale.

Suggested change
await c.env.DB.prepare(
`UPDATE user
SET notify_product_emails = ?, notify_marketing_emails = ?, updatedAt = ?
WHERE id = ?`,
)
.bind(
parsed.data.productEmails ? 1 : 0,
parsed.data.marketingEmails ? 1 : 0,
Date.now(),
user.id,
)
.run();
const row = await c.env.DB.prepare(
`UPDATE user
SET notify_product_emails = ?, notify_marketing_emails = ?, updatedAt = ?
WHERE id = ?
RETURNING email`,
)
.bind(
parsed.data.productEmails ? 1 : 0,
parsed.data.marketingEmails ? 1 : 0,
Date.now(),
user.id,
)
.first<{ email: string }>();
const email = row?.email ?? user.email;

Comment thread src/workers/account.ts
Comment on lines +112 to +120
await upsertContact(resendEnv, {
email: user.email,
unsubscribed: !parsed.data.marketingEmails,
}).catch((err) => {
console.warn('resend marketing-pref mirror failed', {
userId: user.id,
error: err instanceof Error ? err.message : String(err),
});
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

Mirroring the preference to Resend is a side effect that doesn't need to block the user's request. Using c.executionCtx.waitUntil() allows the response to be sent immediately while the background task completes, improving the perceived performance of the settings update.

    c.executionCtx.waitUntil(
      upsertContact(resendEnv, {
        email,
        unsubscribed: !parsed.data.marketingEmails,
      }).catch((err) => {
        console.warn('resend marketing-pref mirror failed', {
          userId: user.id,
          error: err instanceof Error ? err.message : String(err),
        });
      }),
    );

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9872859e8d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/workers/account.ts
Comment on lines +112 to +115
await upsertContact(resendEnv, {
email: user.email,
unsubscribed: !parsed.data.marketingEmails,
}).catch((err) => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Check Resend upsert result before treating update as synced

/api/account/notifications awaits upsertContact(...).catch(...), but upsertContact reports HTTP/network failures via { ok: false, ... } return values rather than throwing, so this catch path is usually never hit. In cases like invalid Resend credentials or Resend API errors, the endpoint still returns 200 and the UI shows success while the marketing opt-out is not mirrored, leaving contacts subscribed in Resend despite the saved preference; inspect the returned ResendResult and handle non-ok outcomes explicitly.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

conductor Conductor-managed PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants