UNPKG

@shopify/shopify-app-remix

Version:

Shopify Remix - to simplify the building of Shopify Apps with Remix

38 lines (35 loc) 1.47 kB
import { redirect } from '@remix-run/server-runtime'; function validateShopAndHostParams(params, request) { const { api, config, logger } = params; if (config.isEmbeddedApp) { const url = new URL(request.url); const shop = api.utils.sanitizeShop(url.searchParams.get('shop')); if (!shop) { logger.debug('Missing or invalid shop, redirecting to login path', { shop, }); throw redirectToLoginPath(request, params); } const host = api.utils.sanitizeHost(url.searchParams.get('host')); if (!host) { logger.debug('Invalid host, redirecting to login path', { shop, host: url.searchParams.get('host'), }); throw redirectToLoginPath(request, params); } } } function redirectToLoginPath(request, params) { const { config, logger } = params; const { pathname } = new URL(request.url); if (pathname === config.auth.loginPath) { const message = `Detected call to shopify.authenticate.admin() from configured login path ` + `('${config.auth.loginPath}'), please make sure to call shopify.login() from that route instead.`; logger.debug(message); throw new Response(message, { status: 500 }); } throw redirect(config.auth.loginPath); } export { validateShopAndHostParams }; //# sourceMappingURL=validate-shop-and-host-params.mjs.map