diff --git a/src/routes/_authenticated.tsx b/src/routes/_authenticated.tsx
index 6a2d547..3f8ca5a 100644
--- a/src/routes/_authenticated.tsx
+++ b/src/routes/_authenticated.tsx
@@ -1,15 +1,14 @@
-import { Navigate, Outlet, createFileRoute } from "@tanstack/react-router";
-import { useConvexAuth } from "convex/react";
+import { Outlet, createFileRoute, redirect } from "@tanstack/react-router";
export const Route = createFileRoute("/_authenticated")({
+ beforeLoad: async ({ context }) => {
+ const isAuthenticated = await context.auth;
+ if (!isAuthenticated) throw redirect({ to: "/signin" });
+ },
component: AuthenticatedRoute,
});
function AuthenticatedRoute() {
- const { isAuthenticated } = useConvexAuth();
-
- if (!isAuthenticated) return ;
-
return (
diff --git a/src/routes/_unauthenticated.tsx b/src/routes/_unauthenticated.tsx
index 71e4f12..83edd70 100644
--- a/src/routes/_unauthenticated.tsx
+++ b/src/routes/_unauthenticated.tsx
@@ -1,14 +1,9 @@
-import { Navigate, Outlet, createFileRoute } from "@tanstack/react-router";
-import { useConvexAuth } from "convex/react";
+import { Outlet, createFileRoute } from "@tanstack/react-router";
export const Route = createFileRoute("/_unauthenticated")({
component: UnauthenticatedRoute,
});
function UnauthenticatedRoute() {
- const { isAuthenticated } = useConvexAuth();
-
- if (isAuthenticated) return ;
-
return ;
}
diff --git a/src/routes/_unauthenticated/signin.tsx b/src/routes/_unauthenticated/signin.tsx
index 9b3cd6f..9ed0b0f 100644
--- a/src/routes/_unauthenticated/signin.tsx
+++ b/src/routes/_unauthenticated/signin.tsx
@@ -15,13 +15,17 @@ import {
TooltipTrigger,
} from "@/components/common";
import { useAuthActions } from "@convex-dev/auth/react";
-import { createFileRoute, useNavigate } from "@tanstack/react-router";
+import { createFileRoute, redirect, useNavigate } from "@tanstack/react-router";
import { ConvexError } from "convex/values";
import { ChevronLeft } from "lucide-react";
import { useState } from "react";
import type { Key } from "react-aria";
export const Route = createFileRoute("/_unauthenticated/signin")({
+ beforeLoad: async ({ context }) => {
+ const isAuthenticated = await context.auth;
+ if (isAuthenticated) throw redirect({ to: "/" });
+ },
component: LoginRoute,
});