From cfda1e3b98f93f752cf0b36df9cf87287ab908e0 Mon Sep 17 00:00:00 2001 From: lorcan-codes <126797224+lorcan-codes@users.noreply.github.com> Date: Thu, 26 Oct 2023 15:25:39 +0500 Subject: [PATCH] Use env values in configs --- .github/workflows/netlify-cms.yml | 1 + workspaces/netlify-cms-auth/src/callback.ts | 8 ++++++-- workspaces/netlify-cms-auth/src/env.ts | 5 +++-- workspaces/netlify-cms/src/App.tsx | 2 ++ 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/workflows/netlify-cms.yml b/.github/workflows/netlify-cms.yml index 2af2fd17e5..72fe49e369 100644 --- a/.github/workflows/netlify-cms.yml +++ b/.github/workflows/netlify-cms.yml @@ -51,6 +51,7 @@ jobs: VITE_GIT_BRANCH_NAME: ${{ github.ref_name }} VITE_API_BASE_URL: https://${{ env.GITHUB_REF_SLUG_URL }}.starknet-website.pages.dev/api VITE_DATA_URL: https://${{ env.GITHUB_REF_SLUG_URL }}.starknet-website.pages.dev/data + VITE_BACKEND_AUTH_URL: https://auth.clivado.com - name: Deploy Netlify CMS uses: cloudflare/pages-action@1 diff --git a/workspaces/netlify-cms-auth/src/callback.ts b/workspaces/netlify-cms-auth/src/callback.ts index 2f0313f693..ae3964983e 100644 --- a/workspaces/netlify-cms-auth/src/callback.ts +++ b/workspaces/netlify-cms-auth/src/callback.ts @@ -25,6 +25,7 @@ export async function callback( postMessageHTML({ status: "success", data: { token, provider }, + env, }), { headers: { @@ -37,6 +38,7 @@ export async function callback( postMessageHTML({ status: "error", data: e, + env, }), { headers: { @@ -50,9 +52,10 @@ export async function callback( interface PostMessageHTMLArgs { status: "success" | "error"; data: any; + env: Env; } -function postMessageHTML({ status, data }: PostMessageHTMLArgs) { +function postMessageHTML({ status, data, env }: PostMessageHTMLArgs) { return ` @@ -62,7 +65,8 @@ function postMessageHTML({ status, data }: PostMessageHTMLArgs) { const allowedOrigin = ( message.origin === 'http://localhost:1234' || message.origin === 'http://127.0.0.1:1234' || - /^https:\\/\\/[-_\\w]+\\.starknet-netlify-cms\\.pages\\.dev$/.test(message.origin) + /^https:\\/\\/[-_\\w]+\\.starknet-netlify-cms\\.pages\\.dev$/.test(message.origin) || + message.origin === '${env.CMS_URL}' ); if (!allowedOrigin) return; diff --git a/workspaces/netlify-cms-auth/src/env.ts b/workspaces/netlify-cms-auth/src/env.ts index 8050439f19..1642beadb7 100644 --- a/workspaces/netlify-cms-auth/src/env.ts +++ b/workspaces/netlify-cms-auth/src/env.ts @@ -1,4 +1,5 @@ export interface Env { - OAUTH_GITHUB_CLIENT_ID: string - OAUTH_GITHUB_CLIENT_SECRET: string + OAUTH_GITHUB_CLIENT_ID: string; + OAUTH_GITHUB_CLIENT_SECRET: string; + CMS_URL: string; } diff --git a/workspaces/netlify-cms/src/App.tsx b/workspaces/netlify-cms/src/App.tsx index 96a5e7b1c2..e244aadfde 100644 --- a/workspaces/netlify-cms/src/App.tsx +++ b/workspaces/netlify-cms/src/App.tsx @@ -110,6 +110,8 @@ export default function App() { backend: { ...CMSConfig.backend, branch, + base_url: + import.meta.env.VITE_BACKEND_AUTH_URL || CMSConfig.backend.base_url, }, }, });