-
Notifications
You must be signed in to change notification settings - Fork 0
POC of the auto unsubscribe functionality #1
base: replay-376-base-e745a15
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,7 +4,10 @@ import React, { useCallback, useState } from "react"; | |||||||||||||||||||||||||||||||
| import { toast } from "sonner"; | ||||||||||||||||||||||||||||||||
| import type { PostHog } from "posthog-js/react"; | ||||||||||||||||||||||||||||||||
| import { onAutoArchive, onDeleteFilter } from "@/utils/actions/client"; | ||||||||||||||||||||||||||||||||
| import { setNewsletterStatusAction } from "@/utils/actions/unsubscriber"; | ||||||||||||||||||||||||||||||||
| import { | ||||||||||||||||||||||||||||||||
| setNewsletterStatusAction, | ||||||||||||||||||||||||||||||||
| unsubscribeAction, | ||||||||||||||||||||||||||||||||
| } from "@/utils/actions/unsubscriber"; | ||||||||||||||||||||||||||||||||
| import { decrementUnsubscribeCreditAction } from "@/utils/actions/premium"; | ||||||||||||||||||||||||||||||||
| import { NewsletterStatus } from "@prisma/client"; | ||||||||||||||||||||||||||||||||
| import { cleanUnsubscribeLink } from "@/utils/parse/parseHtml.client"; | ||||||||||||||||||||||||||||||||
|
|
@@ -54,6 +57,10 @@ export function useUnsubscribe<T extends Row>({ | |||||||||||||||||||||||||||||||
| posthog.capture("Clicked Unsubscribe"); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if (item.status === NewsletterStatus.UNSUBSCRIBED) { | ||||||||||||||||||||||||||||||||
| if (item.lastUnsubscribeLink) { | ||||||||||||||||||||||||||||||||
| await unsubscribeAction({ url: item.lastUnsubscribeLink }); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
Comment on lines
+60
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical logic error: unsubscribeAction called in the wrong flow. Lines 59-68 handle the case where the newsletter is already unsubscribed ( The 🐛 Proposed fix if (item.status === NewsletterStatus.UNSUBSCRIBED) {
- if (item.lastUnsubscribeLink) {
- await unsubscribeAction({ url: item.lastUnsubscribeLink });
- }
-
await setNewsletterStatusAction({
newsletterEmail: item.name,
status: null,
});
await mutate();
} else {
+ if (item.lastUnsubscribeLink) {
+ await unsubscribeAction({ url: item.lastUnsubscribeLink });
+ }
await unsubscribeAndArchive(item.name, mutate, refetchPremium);
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI AgentsMissing error handling for external API call. The Consider adding explicit error handling and user notification. 🛡️ Suggested improvement if (item.lastUnsubscribeLink) {
- await unsubscribeAction({ url: item.lastUnsubscribeLink });
+ const result = await unsubscribeAction({ url: item.lastUnsubscribeLink });
+ if (result.error) {
+ toast.error("Failed to unsubscribe. Please try again.");
+ setUnsubscribeLoading(false);
+ return;
+ }
}
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| await setNewsletterStatusAction({ | ||||||||||||||||||||||||||||||||
| newsletterEmail: item.name, | ||||||||||||||||||||||||||||||||
| status: null, | ||||||||||||||||||||||||||||||||
|
|
@@ -72,6 +79,7 @@ export function useUnsubscribe<T extends Row>({ | |||||||||||||||||||||||||||||||
| hasUnsubscribeAccess, | ||||||||||||||||||||||||||||||||
| item.name, | ||||||||||||||||||||||||||||||||
| item.status, | ||||||||||||||||||||||||||||||||
| item.lastUnsubscribeLink, | ||||||||||||||||||||||||||||||||
| mutate, | ||||||||||||||||||||||||||||||||
| refetchPremium, | ||||||||||||||||||||||||||||||||
| posthog, | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,6 +4,7 @@ import { auth } from "@/app/api/auth/[...nextauth]/auth"; | |||||||||||||||||||||||
| import prisma from "@/utils/prisma"; | ||||||||||||||||||||||||
| import type { NewsletterStatus } from "@prisma/client"; | ||||||||||||||||||||||||
| import { withActionInstrumentation } from "@/utils/actions/middleware"; | ||||||||||||||||||||||||
| import { env } from "@/env"; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| export const setNewsletterStatusAction = withActionInstrumentation( | ||||||||||||||||||||||||
| "setNewsletterStatus", | ||||||||||||||||||||||||
|
|
@@ -30,3 +31,23 @@ export const setNewsletterStatusAction = withActionInstrumentation( | |||||||||||||||||||||||
| }); | ||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| export const unsubscribeAction = withActionInstrumentation( | ||||||||||||||||||||||||
| "unsubscribe", | ||||||||||||||||||||||||
| async (options: { url: string }) => { | ||||||||||||||||||||||||
| const session = await auth(); | ||||||||||||||||||||||||
| if (!session?.user.email) return { error: "Not logged in" }; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const { url } = options; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const response = await fetch( | ||||||||||||||||||||||||
| `${env.UNSUBSCRIBER_API_URL}/unsubscribe?url=${url}&email=${session.user.email}`, | ||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Major: Sensitive data exposure in URL. The user's email address is included in the URL query string. GET requests are logged in server logs, proxy logs, and browser history, exposing PII unnecessarily. Use a POST request with the email in the request body instead. 🤖 Prompt for AI Agents |
||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||
|
Comment on lines
+43
to
+45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: HTTP method mismatch and missing URL encoding. The client makes a GET request with query parameters, but the server endpoint at Additionally, the 🔧 Proposed fix- const response = await fetch(
- `${env.UNSUBSCRIBER_API_URL}/unsubscribe?url=${url}&email=${session.user.email}`,
- );
+ const response = await fetch(
+ `${env.UNSUBSCRIBER_API_URL}/unsubscribe`,
+ {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ url, email: session.user.email }),
+ }
+ );📝 Committable suggestion
Suggested change
🤖 Prompt for AI AgentsMajor: Missing validation for optional environment variable.
🛡️ Proposed fix const { url } = options;
+ if (!env.UNSUBSCRIBER_API_URL) {
+ return { error: "Unsubscriber service not configured" };
+ }
+
const response = await fetch(
`${env.UNSUBSCRIBER_API_URL}/unsubscribe`,
🤖 Prompt for AI Agents |
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| if (!response.ok) { | ||||||||||||||||||||||||
| return { error: "Failed to unsubscribe" }; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| return { success: true }; | ||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: admin-coderabbit/inbox-zero
Length of output: 220
🏁 Script executed:
Repository: admin-coderabbit/inbox-zero
Length of output: 2021
🏁 Script executed:
Repository: admin-coderabbit/inbox-zero
Length of output: 556
Critical: Unused parameter in function signature.
The
emailparameter is accepted in the function signature (line 208) but never used anywhere in the function body (lines 213-276). It's not passed toanalyzePageWithAI,performUnsubscribeActions,performFallbackUnsubscribe, or any other helper function, and is never referenced in any form.Either implement the email parameter by passing it to the appropriate helper functions (if needed for form filling or AI context), or remove it to avoid confusion and breaking changes.
🤖 Prompt for AI Agents