diff options
Diffstat (limited to 'packages/anastasis-webui/src/pages/home/AddingProviderScreen/state.ts')
-rw-r--r-- | packages/anastasis-webui/src/pages/home/AddingProviderScreen/state.ts | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/packages/anastasis-webui/src/pages/home/AddingProviderScreen/state.ts b/packages/anastasis-webui/src/pages/home/AddingProviderScreen/state.ts index f80f1c464..30e4d750d 100644 --- a/packages/anastasis-webui/src/pages/home/AddingProviderScreen/state.ts +++ b/packages/anastasis-webui/src/pages/home/AddingProviderScreen/state.ts @@ -76,14 +76,23 @@ export default function useComponentState({ useEffect(() => { if (timeout.current) clearTimeout(timeout.current); timeout.current = setTimeout(async () => { - const url = providerURL.endsWith("/") ? providerURL : providerURL + "/"; - if (!providerURL || authProviders.includes(url)) return; + let url = providerURL; + if (!url || authProviders.includes(url)) return; + if (url && !url.match(/^(https?:)\/\/.+\/(?:config)?$/iu)) + return setError( + "Malformed URL: Must be an HTTP(S) URL ending with a /", + ); + if (url.endsWith("/config")) url = url.substring(0, url.length - 6); try { setTesting(true); await testProvider(url, providerType); setError(""); } catch (e) { if (e instanceof Error) setError(e.message); + else + throw new Error( + `Unexpected Error Type: ${typeof e} - Cannot handle. Error: ${e}`, + ); } setTesting(false); }, 200); @@ -114,11 +123,12 @@ export default function useComponentState({ let errors = !providerURL ? "Add provider URL" : undefined; let url: string | undefined; - try { - url = new URL("", providerURL).href; - } catch { - errors = "Check the URL"; - } + // We'll validate it in testProvider & via a regex above - there's no need in this :) + // try { + // url = new URL("", providerURL).href; + // } catch { + // errors = "Check the URL"; + // } const _url = url; if (!!error && !errors) { |