Clear cached subscriptions on uninstall so a quick reinstall asks for a plan
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
884481e305
commit
b7dfe00200
@ -23,6 +23,11 @@ export interface ActiveSubscription {
|
||||
const CACHE_MS = 5 * 60 * 1000;
|
||||
const cache = new Map<string, { at: number; sub: ActiveSubscription }>();
|
||||
|
||||
/** Called on app/uninstalled: the subscription is cancelled then, so a quick reinstall must not see a cached plan. */
|
||||
export function forgetSubscriptions() {
|
||||
cache.clear();
|
||||
}
|
||||
|
||||
export function partnerApiConfigured() {
|
||||
return !!(process.env.SHOPIFY_PARTNER_ORG_ID && process.env.SHOPIFY_PARTNER_API_ACCESS_TOKEN && process.env.SHOPIFY_APP_GID);
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
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
|
||||
@ -10,6 +11,7 @@ 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();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user