Skip to content

Commit 08b4cea

Browse files
committed
fix: Guard more sign-in routes
1 parent 69f8d75 commit 08b4cea

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

src/components/Navbar.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ function AnonymousNav() {
231231
return (
232232
<div className="flex items-center justify-between">
233233
<div className="inline-block">
234-
<Link to="/">
234+
<Link to="/sign-in">
235235
<Logo />
236236
<span className="text-grey text-xs inline-block pl-2">{import.meta.env.VITE_STUDIO_VERSION}</span>
237237
</Link>

src/features/instance/instanceLayoutRoute.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { clusterLayoutRoute } from '@/features/cluster/routes';
22
import { InstanceLayout } from '@/features/instance/InstanceLayout';
33
import { getInstanceInfoQueryOptions } from '@/features/cluster/queries/getInstanceInfoQuery';
4-
import { currentUrlAfterHash } from '@/lib/urls/currentUrlAfterHash';
4+
import { buildRedirectInSearch } from '@/lib/urls/buildRedirectInSearch';
55
import { dashboardLayout } from '@/router/dashboardRoute';
66
import { createRoute, redirect } from '@tanstack/react-router';
77

@@ -22,7 +22,7 @@ export function createInstanceLayoutRoute(mode: 'local' | 'cluster' | 'instance'
2222
const auth = context.authentication[params.clusterId];
2323
if (!auth || (!auth.isLoading && !auth.user)) {
2424
const to = `/${params.organizationId}/${params.clusterId}/sign-in`;
25-
throw redirect({ to, search: currentUrlAfterHash() !== '/' && { redirect: currentUrlAfterHash() } });
25+
throw redirect({ to, search: buildRedirectInSearch() });
2626
}
2727
return await context.queryClient.ensureQueryData(getInstanceInfoQueryOptions(params));
2828
},
@@ -36,7 +36,7 @@ export function createInstanceLayoutRoute(mode: 'local' | 'cluster' | 'instance'
3636
const auth = context.authentication[params.instanceId];
3737
if (!auth || (!auth.isLoading && !auth.user)) {
3838
const to = `/${params.organizationId}/${params.clusterId}/instance/${params.instanceId}/sign-in`;
39-
throw redirect({ to, search: currentUrlAfterHash() !== '/' && { redirect: currentUrlAfterHash() } });
39+
throw redirect({ to, search: buildRedirectInSearch() });
4040
}
4141
return await context.queryClient.ensureQueryData(getInstanceInfoQueryOptions(params));
4242
},
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { currentUrlAfterHash } from '@/lib/urls/currentUrlAfterHash';
2+
3+
const ignoredUrls = [
4+
'/',
5+
'/forgot-password',
6+
'/reset-password',
7+
'/sign-in',
8+
'/sign-up',
9+
'/verify-email',
10+
];
11+
12+
export function buildRedirectInSearch() {
13+
const url = currentUrlAfterHash().split('?')[0];
14+
return !ignoredUrls.includes(url) && { redirect: url };
15+
}

src/router/dashboardRoute.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Dashboard } from '@/features/layouts/Dashboard';
22
import { OverallAppSignIn } from '@/lib/authStore';
3-
import { currentUrlAfterHash } from '@/lib/urls/currentUrlAfterHash';
3+
import { buildRedirectInSearch } from '@/lib/urls/buildRedirectInSearch';
44
import { rootRoute } from '@/router/rootRoute';
55
import { createRoute, redirect } from '@tanstack/react-router';
66

@@ -13,7 +13,7 @@ export const dashboardLayout = createRoute({
1313
if (auth && !auth.isLoading && !auth.user) {
1414
throw redirect({
1515
to: '/sign-in',
16-
search: currentUrlAfterHash() !== '/' && { redirect: currentUrlAfterHash() },
16+
search: buildRedirectInSearch(),
1717
});
1818
}
1919
},

0 commit comments

Comments
 (0)