Skip to content

Commit 5a90228

Browse files
authored
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
1 parent 8ffe0e2 commit 5a90228

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

site/src/pages/LoginPage/LoginPage.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,29 @@ export const LoginPage: FC = () => {
2121
const navigate = useNavigate();
2222

2323
if (isSignedIn) {
24+
// If the redirect is going to a workspace application, and we
25+
// are missing authentication, then we need to change the href location
26+
// to trigger a HTTP request. This allows the BE to generate the auth
27+
// cookie required.
28+
// If no redirect is present, then ignore this branched logic.
29+
if (redirectTo !== "" && redirectTo !== "/") {
30+
try {
31+
// This catches any absolute redirects. Relative redirects
32+
// will fail the try/catch. Subdomain apps are absolute redirects.
33+
const redirectURL = new URL(redirectTo);
34+
if (redirectURL.host !== window.location.host) {
35+
window.location.href = redirectTo;
36+
return <></>;
37+
}
38+
} catch {
39+
// Do nothing
40+
}
41+
// Path based apps.
42+
if (redirectTo.includes("/apps/")) {
43+
window.location.href = redirectTo;
44+
return <></>;
45+
}
46+
}
2447
return <Navigate to={redirectTo} replace />;
2548
} else if (isConfiguringTheFirstUser) {
2649
return <Navigate to="/setup" replace />;

0 commit comments

Comments
 (0)