File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed
components/features/auths/UnauthenticatedBoundary Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change 1+ import { Navigate } from "@tanstack/react-router" ;
2+ import { ConvexError } from "convex/values" ;
3+ import type { ReactNode } from "react" ;
4+ import { ErrorBoundary } from "@/src/components/ui/ErrorBoundary" ;
5+
6+ type Props = {
7+ children : ReactNode ;
8+ } ;
9+
10+ const isUnauthenticatedError = ( error : Error ) => error instanceof ConvexError && error . data === "Unauthenticated" ;
11+
12+ export const UnauthenticatedBoundary = ( { children } : Props ) => {
13+ return (
14+ < ErrorBoundary
15+ fallback = { ( error ) => {
16+ if ( isUnauthenticatedError ( error ) ) {
17+ return < Navigate to = "/" replace /> ;
18+ }
19+ throw error ;
20+ } }
21+ >
22+ { children }
23+ </ ErrorBoundary >
24+ ) ;
25+ } ;
Original file line number Diff line number Diff line change 11import { Box } from "@chakra-ui/react" ;
22import { createFileRoute , Outlet } from "@tanstack/react-router" ;
33import { AuthGuard } from "@/src/components/features/auths/AuthGuard" ;
4+ import { UnauthenticatedBoundary } from "@/src/components/features/auths/UnauthenticatedBoundary" ;
45import { Header } from "@/src/components/templates/Header" ;
56
67export const Route = createFileRoute ( "/_auth" ) ( {
@@ -10,7 +11,9 @@ export const Route = createFileRoute("/_auth")({
1011function RouteComponent ( ) {
1112 return (
1213 < AuthGuard >
13- < AuthenticatedLayout />
14+ < UnauthenticatedBoundary >
15+ < AuthenticatedLayout />
16+ </ UnauthenticatedBoundary >
1417 </ AuthGuard >
1518 ) ;
1619}
You can’t perform that action at this time.
0 commit comments