From 88bcf5d02c43d9258667ee92eb564e37345d4614 Mon Sep 17 00:00:00 2001 From: Tobias Date: Fri, 6 Dec 2024 09:28:44 +0100 Subject: [PATCH] Onboarding: Guard deployedURL Before, it was possible to provide `https://foo.com/` as input and generate a redirect_uri like `https://foo.com//api/keystatic/github/oauth/callback` which triggers the "The `redirect_uri` is not associated with this application." error by Github. Now the path is merged with the URL correctly for any valid URL input. --- .changeset/nice-parrots-sort.md | 5 +++++ packages/keystatic/src/app/onboarding/setup.tsx | 9 +++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 .changeset/nice-parrots-sort.md diff --git a/.changeset/nice-parrots-sort.md b/.changeset/nice-parrots-sort.md new file mode 100644 index 000000000..301aba2b4 --- /dev/null +++ b/.changeset/nice-parrots-sort.md @@ -0,0 +1,5 @@ +--- +'@keystatic/core': patch +--- + +During onboarding, make sure the Deployed App URL does not have double slashes. diff --git a/packages/keystatic/src/app/onboarding/setup.tsx b/packages/keystatic/src/app/onboarding/setup.tsx index e785ca74b..5d1dc58b5 100644 --- a/packages/keystatic/src/app/onboarding/setup.tsx +++ b/packages/keystatic/src/app/onboarding/setup.tsx @@ -77,7 +77,7 @@ export function KeystaticSetup(props: { config: GitHubConfig }) { parseRepoConfig(props.config.storage.repo).owner } Keystatic`, url: deployedURL - ? `${deployedURL}/keystatic` + ? new URL('/keystatic', deployedURL).toString() : `${window.location.origin}/keystatic`, public: true, redirect_url: `${window.location.origin}/api/keystatic/github/created-app`, @@ -85,7 +85,12 @@ export function KeystaticSetup(props: { config: GitHubConfig }) { `${window.location.origin}/api/keystatic/github/oauth/callback`, `http://127.0.0.1/api/keystatic/github/oauth/callback`, ...(deployedURL - ? [`${deployedURL}/api/keystatic/github/oauth/callback`] + ? [ + new URL( + '/api/keystatic/github/oauth/callback', + deployedURL + ).toString(), + ] : []), ], request_oauth_on_install: true,