@@ -49,6 +38,26 @@ function RootLayout() {
);
}
+function PendingComponent() {
+ return (
+
+ );
+}
+
export const rootRoute = createRootRoute({
component: RootLayout,
+ pendingComponent: PendingComponent,
+ beforeLoad: async ({ location }) => {
+ if (location.pathname === '/login') return;
+ try {
+ await queryClient.ensureQueryData({
+ ...trpc.auth.me.queryOptions(),
+ retry: false,
+ });
+ } catch {
+ throw redirect({ to: '/login' });
+ }
+ },
});
diff --git a/web/src/routes/login.tsx b/web/src/routes/login.tsx
index 261ff7cd..45ee9d5b 100644
--- a/web/src/routes/login.tsx
+++ b/web/src/routes/login.tsx
@@ -32,8 +32,8 @@ function LoginPage() {
return;
}
- await queryClient.refetchQueries({ queryKey: trpc.auth.me.queryOptions().queryKey });
- navigate({ to: '/' });
+ await queryClient.invalidateQueries({ queryKey: trpc.auth.me.queryOptions().queryKey });
+ navigate({ to: '/', replace: true });
} catch {
setError('Network error');
} finally {