Add better redirects

This commit is contained in:
Nate Kelley 2025-09-04 13:59:50 -06:00
parent 40f2c1a27e
commit f80bb3b790
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
5 changed files with 31 additions and 15 deletions

View File

@ -382,7 +382,7 @@ const ResetPasswordLink: React.FC<{ email: string; tabIndex?: number }> = ({ ema
const scrubbedEmail = useMemo(() => {
if (!email || !isValidEmail(email)) return '';
try {
return encodeURIComponent(email.trim());
return email.trim();
} catch (error) {
console.error('Error encoding email:', error);
return '';

View File

@ -15,6 +15,7 @@ import { Route as rootRouteImport } from './routes/__root'
import { Route as AuthRouteImport } from './routes/auth'
import { Route as AppRouteImport } from './routes/app'
import { Route as IndexRouteImport } from './routes/index'
import { Route as AppIndexRouteImport } from './routes/app/index'
import { Route as AuthResetPasswordRouteImport } from './routes/auth.reset-password'
import { Route as AuthLogoutRouteImport } from './routes/auth.logout'
import { Route as AuthLoginRouteImport } from './routes/auth.login'
@ -171,6 +172,11 @@ const IndexRoute = IndexRouteImport.update({
path: '/',
getParentRoute: () => rootRouteImport,
} as any)
const AppIndexRoute = AppIndexRouteImport.update({
id: '/',
path: '/',
getParentRoute: () => AppRoute,
} as any)
const AuthResetPasswordRoute = AuthResetPasswordRouteImport.update({
id: '/reset-password',
path: '/reset-password',
@ -903,6 +909,7 @@ export interface FileRoutesByFullPath {
'/auth/login': typeof AuthLoginRoute
'/auth/logout': typeof AuthLogoutRoute
'/auth/reset-password': typeof AuthResetPasswordRoute
'/app/': typeof AppIndexRoute
'/app/home': typeof AppAppHomeRoute
'/embed/dashboard/$dashboardId': typeof EmbedDashboardDashboardIdRoute
'/embed/metric/$metricId': typeof EmbedMetricMetricIdRoute
@ -1001,8 +1008,8 @@ export interface FileRoutesByFullPath {
}
export interface FileRoutesByTo {
'/': typeof IndexRoute
'/app': typeof AppSettingsRestricted_layoutAdmin_onlyRouteWithChildren
'/auth': typeof AuthRouteWithChildren
'/app': typeof AppSettingsRestricted_layoutAdmin_onlyRouteWithChildren
'/auth/login': typeof AuthLoginRoute
'/auth/logout': typeof AuthLogoutRoute
'/auth/reset-password': typeof AuthResetPasswordRoute
@ -1095,6 +1102,7 @@ export interface FileRoutesById {
'/auth/login': typeof AuthLoginRoute
'/auth/logout': typeof AuthLogoutRoute
'/auth/reset-password': typeof AuthResetPasswordRoute
'/app/': typeof AppIndexRoute
'/app/_app/_asset': typeof AppAppAssetRouteWithChildren
'/app/_app/home': typeof AppAppHomeRoute
'/app/_settings/_permissions': typeof AppSettingsPermissionsRouteWithChildren
@ -1214,6 +1222,7 @@ export interface FileRouteTypes {
| '/auth/login'
| '/auth/logout'
| '/auth/reset-password'
| '/app/'
| '/app/home'
| '/embed/dashboard/$dashboardId'
| '/embed/metric/$metricId'
@ -1312,8 +1321,8 @@ export interface FileRouteTypes {
fileRoutesByTo: FileRoutesByTo
to:
| '/'
| '/app'
| '/auth'
| '/app'
| '/auth/login'
| '/auth/logout'
| '/auth/reset-password'
@ -1405,6 +1414,7 @@ export interface FileRouteTypes {
| '/auth/login'
| '/auth/logout'
| '/auth/reset-password'
| '/app/'
| '/app/_app/_asset'
| '/app/_app/home'
| '/app/_settings/_permissions'
@ -1569,6 +1579,13 @@ declare module '@tanstack/react-router' {
preLoaderRoute: typeof IndexRouteImport
parentRoute: typeof rootRouteImport
}
'/app/': {
id: '/app/'
path: '/'
fullPath: '/app/'
preLoaderRoute: typeof AppIndexRouteImport
parentRoute: typeof AppRoute
}
'/auth/reset-password': {
id: '/auth/reset-password'
path: '/reset-password'
@ -3098,11 +3115,13 @@ const AppSettingsRouteWithChildren = AppSettingsRoute._addFileChildren(
interface AppRouteChildren {
AppAppRoute: typeof AppAppRouteWithChildren
AppSettingsRoute: typeof AppSettingsRouteWithChildren
AppIndexRoute: typeof AppIndexRoute
}
const AppRouteChildren: AppRouteChildren = {
AppAppRoute: AppAppRouteWithChildren,
AppSettingsRoute: AppSettingsRouteWithChildren,
AppIndexRoute: AppIndexRoute,
}
const AppRouteWithChildren = AppRoute._addFileChildren(AppRouteChildren)

View File

@ -16,6 +16,7 @@ export const Route = createFileRoute('/app')({
const isAnonymous = context.user?.is_anonymous;
if (!hasUser || isAnonymous) {
//Hmmmm... maybe this is weird... maybe i'll remove it
const isAssetRoute = matches.some((match) => match.routeId === '/app/_app/_asset');
if (isAssetRoute) {
const route = embedAssetToRegularAsset(matches);
@ -25,11 +26,6 @@ export const Route = createFileRoute('/app')({
}
throw redirect({ to: '/auth/login' });
}
// Only redirect if landing directly on /app (not on nested routes)
if (matches.length === 2 && matches[1].fullPath === '/app') {
throw redirect({ to: '/app/home' });
}
},
loader: async ({ context }) => {
const { queryClient } = context;

View File

@ -0,0 +1,7 @@
import { createFileRoute, redirect } from '@tanstack/react-router';
export const Route = createFileRoute('/app/')({
beforeLoad: async () => {
throw redirect({ to: '/app/home' });
},
});

View File

@ -1,4 +1,4 @@
import { createFileRoute, redirect } from '@tanstack/react-router';
import { createFileRoute } from '@tanstack/react-router';
import { z } from 'zod';
import { prefetchGetMyUserInfo } from '@/api/buster_rest/users';
import { ResetEmailForm } from '@/components/features/auth/ResetEmailForm';
@ -18,12 +18,6 @@ export const Route = createFileRoute('/auth/reset-password')({
validateSearch: z.object({
email: z.string(),
}),
beforeLoad: async ({ context }) => {
const { user, accessToken } = context;
if (!user || !accessToken || user.is_anonymous || !user.email) {
throw redirect({ to: '/auth/login' });
}
},
loader: async ({ context }) => {
const user = await prefetchGetMyUserInfo(context.queryClient);
return {