Skip to content

Commit

Permalink
Add ALLOWED_DOMAIN_PATTERN env (#200)
Browse files Browse the repository at this point in the history
Co-authored-by: Krzysztof Żuraw <9116238+krzysztofzuraw@users.noreply.github.com>
  • Loading branch information
lkostrowski and krzysztofzuraw authored Feb 12, 2024
1 parent 7f4e5eb commit c69f6b8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/itchy-bikes-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"saleor-app-payment-stripe": minor
---

Added "ALLOWED_DOMAIN_PATTERN" env that can be used to allow/disallow specific Saleor instances
2 changes: 2 additions & 0 deletions src/lib/env.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const env = createEnv({
UPSTASH_TOKEN: z.string().optional(),
REST_APL_ENDPOINT: z.string().optional(),
REST_APL_TOKEN: z.string().optional(),
ALLOWED_DOMAIN_PATTERN: z.string().optional(),
},

/*
Expand Down Expand Up @@ -56,5 +57,6 @@ export const env = createEnv({
UPSTASH_TOKEN: process.env.UPSTASH_TOKEN,
REST_APL_ENDPOINT: process.env.REST_APL_ENDPOINT,
REST_APL_TOKEN: process.env.REST_APL_TOKEN,
ALLOWED_DOMAIN_PATTERN: process.env.ALLOWED_DOMAIN_PATTERN,
},
});
24 changes: 12 additions & 12 deletions src/pages/api/register.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { createAppRegisterHandler } from "@saleor/app-sdk/handlers/next";

import { saleorApp } from "../../saleor-app";
import { env } from "@/lib/env.mjs";

const allowedUrlsPattern = env.ALLOWED_DOMAIN_PATTERN;

/**
* Required endpoint, called by Saleor to install app.
Expand All @@ -9,17 +12,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;
},
],
});

0 comments on commit c69f6b8

Please sign in to comment.