Skip to content

Commit

Permalink
Reference value instead of object
Browse files Browse the repository at this point in the history
  • Loading branch information
evadecker committed Dec 2, 2024
1 parent 1f13ef0 commit 9f44e08
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
14 changes: 9 additions & 5 deletions src/routes/_authenticated.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import { Outlet, createFileRoute, redirect } from "@tanstack/react-router";
import { Authenticated } from "convex/react";

export const Route = createFileRoute("/_authenticated")({
beforeLoad: async ({ context }) => {
const isAuthenticated = await context.auth;
if (!isAuthenticated) throw redirect({ to: "/signin" });
const { isAuthenticated, isLoading } = await context.auth;
console.log("isAuthenticated", isAuthenticated);
if (!isLoading && !isAuthenticated) throw redirect({ to: "/signin" });
},
component: AuthenticatedRoute,
});

function AuthenticatedRoute() {
return (
<main className="text-gray-normal">
<Outlet />
</main>
<Authenticated>
<main className="text-gray-normal">
<Outlet />
</main>
</Authenticated>
);
}
4 changes: 2 additions & 2 deletions src/routes/_unauthenticated/signin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ 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: "/" });
const { isAuthenticated, isLoading } = await context.auth;
if (!isLoading && isAuthenticated) throw redirect({ to: "/" });
},
component: LoginRoute,
});
Expand Down

0 comments on commit 9f44e08

Please sign in to comment.