bundle-offers-app/app/routes/webhooks.app.uninstalled.tsx
metatroncubeswdev b7dfe00200 Clear cached subscriptions on uninstall so a quick reinstall asks for a plan
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-30 21:33:44 -04:00

19 lines
1.0 KiB
TypeScript

import type { ActionFunctionArgs } from "react-router";
import { authenticate } from "../shopify.server";
import db from "../db.server";
import { forgetSubscriptions } from "../lib/partner.server";
// The access token is already revoked here, so the app can't call the Admin API. Shopify removes the app's
// functions with the app, so the automatic discount stops applying, and it deletes app-owned ($app and
// app-data) metafields. We mark the shop and keep its data for 48 h, until shop/redact deletes it.
// The in-app "Remove all Offerlyst data" action (Settings) deletes the discount explicitly.
export const action = async ({ request }: ActionFunctionArgs) => {
const { shop, session, topic } = await authenticate.webhook(request);
console.log(`Received ${topic} webhook for ${shop}`);
forgetSubscriptions();
await db.shop.updateMany({ where: { domain: shop }, data: { uninstalledAt: new Date(), discountNodeId: null, nextSyncAt: null } });
if (session) await db.session.deleteMany({ where: { shop } });
return new Response();
};