feat(cloud): sync subscriber preferences on unsubscribe
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
"@kan/api": "workspace:*",
|
||||
"@kan/auth": "workspace:*",
|
||||
"@kan/db": "workspace:^",
|
||||
"@kan/email": "workspace:^",
|
||||
"@kan/logger": "workspace:^",
|
||||
"@kan/shared": "workspace:^",
|
||||
"@lingui/babel-preset-react": "^2.9.2",
|
||||
|
||||
@@ -5,9 +5,13 @@ import { z } from "zod";
|
||||
|
||||
import { withApiLogging } from "@kan/api/utils/apiLogging";
|
||||
import { withRateLimit } from "@kan/api/utils/rateLimit";
|
||||
import { updateSubscriberPreferences } from "@kan/email";
|
||||
import { createLogger } from "@kan/logger";
|
||||
|
||||
import { env } from "~/env";
|
||||
|
||||
const log = createLogger("unsubscribe");
|
||||
|
||||
const requestSchema = z.object({
|
||||
token: z.string().min(1),
|
||||
});
|
||||
@@ -84,6 +88,7 @@ export default withRateLimit(
|
||||
|
||||
const novu = new Novu({ secretKey: env.NOVU_API_KEY });
|
||||
|
||||
let novuFailed = false;
|
||||
try {
|
||||
await novu.subscribers.preferences.update(
|
||||
{
|
||||
@@ -94,6 +99,18 @@ export default withRateLimit(
|
||||
payload.subscriberId,
|
||||
);
|
||||
} catch (error) {
|
||||
novuFailed = true;
|
||||
}
|
||||
|
||||
try {
|
||||
await updateSubscriberPreferences(payload.subscriberId, {
|
||||
email: false,
|
||||
});
|
||||
} catch (error) {
|
||||
log.error({ err: error }, "Error updating subscriber preferences");
|
||||
}
|
||||
|
||||
if (novuFailed) {
|
||||
return res.status(502).json({
|
||||
success: false,
|
||||
error:
|
||||
|
||||
Reference in New Issue
Block a user