-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Reconfigure redirect logic for auth users (#250)
- Loading branch information
Showing
5 changed files
with
27 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"namesake": patch | ||
--- | ||
|
||
Fix redirect logic for authenticated and unauthenticated users |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,20 @@ | ||
import { Navigate, Outlet, createFileRoute } from "@tanstack/react-router"; | ||
import { useConvexAuth } from "convex/react"; | ||
import { Outlet, createFileRoute, redirect } from "@tanstack/react-router"; | ||
import { Authenticated } from "convex/react"; | ||
|
||
export const Route = createFileRoute("/_authenticated")({ | ||
beforeLoad: async ({ context }) => { | ||
const { isAuthenticated, isLoading } = await context.auth; | ||
if (!isLoading && !isAuthenticated) throw redirect({ to: "/signin" }); | ||
}, | ||
component: AuthenticatedRoute, | ||
}); | ||
|
||
function AuthenticatedRoute() { | ||
const { isAuthenticated } = useConvexAuth(); | ||
|
||
if (!isAuthenticated) return <Navigate to="/signin" />; | ||
|
||
return ( | ||
<main className="text-gray-normal"> | ||
<Outlet /> | ||
</main> | ||
<Authenticated> | ||
<main className="text-gray-normal"> | ||
<Outlet /> | ||
</main> | ||
</Authenticated> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <Navigate to="/" />; | ||
|
||
return <Outlet />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters