fix(admin): create or revive the shop record on first admin load instead of 404
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
59de2b9d34
commit
23f259fcc8
@ -1,11 +1,19 @@
|
||||
import { authenticate } from "../shopify.server";
|
||||
import { loadShopConfig } from "../services/config.server";
|
||||
import { ensureShop, loadShopConfig } from "../services/config.server";
|
||||
import { features } from "../services/plans";
|
||||
|
||||
/** Authenticate an embedded admin request and load the shop's config + plan features. */
|
||||
/**
|
||||
* Authenticate an embedded admin request and load the shop's config + plan features.
|
||||
* If the shop record is missing or marked uninstalled (afterAuth didn't run or failed, or a
|
||||
* reinstall), create/revive it here so the merchant never lands on a 404.
|
||||
*/
|
||||
export async function adminContext(request: Request, opts: { fresh?: boolean } = {}) {
|
||||
const ctx = await authenticate.admin(request);
|
||||
const cfg = await loadShopConfig(ctx.session.shop, opts);
|
||||
const cfg = await loadShopConfig(ctx.session.shop, opts).catch(async (e: unknown) => {
|
||||
if (!(e instanceof Response) || e.status !== 404) throw e;
|
||||
await ensureShop(ctx.session.shop, ctx.admin);
|
||||
return loadShopConfig(ctx.session.shop, { fresh: true });
|
||||
});
|
||||
return { ...ctx, cfg, features: features(cfg.shop.plan), actor: `merchant:${ctx.session.onlineAccessInfo?.associated_user?.email ?? "staff"}` };
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user