From 5a90228c60b2ebeca77d72b7b794501d5f27a430 Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Mon, 16 Oct 2023 09:29:25 -0500 Subject: [PATCH] feat: fix 404 on the first app loads when unauthenticated (#10262) * feat: fix 404 on the first app loads when unauthenticated * Update site/src/pages/LoginPage/LoginPage.tsx --- site/src/pages/LoginPage/LoginPage.tsx | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/site/src/pages/LoginPage/LoginPage.tsx b/site/src/pages/LoginPage/LoginPage.tsx index 8eb2b114e3..4a36e2efaa 100644 --- a/site/src/pages/LoginPage/LoginPage.tsx +++ b/site/src/pages/LoginPage/LoginPage.tsx @@ -21,6 +21,29 @@ export const LoginPage: FC = () => { const navigate = useNavigate(); if (isSignedIn) { + // If the redirect is going to a workspace application, and we + // are missing authentication, then we need to change the href location + // to trigger a HTTP request. This allows the BE to generate the auth + // cookie required. + // If no redirect is present, then ignore this branched logic. + if (redirectTo !== "" && redirectTo !== "/") { + try { + // This catches any absolute redirects. Relative redirects + // will fail the try/catch. Subdomain apps are absolute redirects. + const redirectURL = new URL(redirectTo); + if (redirectURL.host !== window.location.host) { + window.location.href = redirectTo; + return <>; + } + } catch { + // Do nothing + } + // Path based apps. + if (redirectTo.includes("/apps/")) { + window.location.href = redirectTo; + return <>; + } + } return ; } else if (isConfiguringTheFirstUser) { return ;