diff --git a/apps/emails-and-messages/src/pages/api/register.ts b/apps/emails-and-messages/src/pages/api/register.ts index 796ec03..382f71a 100644 --- a/apps/emails-and-messages/src/pages/api/register.ts +++ b/apps/emails-and-messages/src/pages/api/register.ts @@ -2,6 +2,8 @@ import { createAppRegisterHandler } from "@saleor/app-sdk/handlers/next"; import { saleorApp } from "../../saleor-app"; +const allowedUrlsPattern = process.env.ALLOWED_DOMAIN_PATTERN; + /** * Required endpoint, called by Saleor to install app. * It will exchange tokens with app, so saleorApp.apl will contain token @@ -9,17 +11,14 @@ import { saleorApp } from "../../saleor-app"; export default createAppRegisterHandler({ apl: saleorApp.apl, allowedSaleorUrls: [ - /** - * You may want your app to work only for certain Saleor instances. - * - * Your app can work for every Saleor that installs it, but you can - * limit it here - * - * By default, every url is allowed. - * - * URL should be a full graphQL address, usually starting with https:// and ending with /graphql/ - * - * Alternatively pass a function - */ + (url) => { + if (allowedUrlsPattern) { + const regex = new RegExp(allowedUrlsPattern); + + return regex.test(url); + } + + return true; + }, ], });