Skip to content

Commit ef3d210

Browse files
yn1323claude
andcommitted
feat: ログイン後画面で Unauthenticated エラー発生時に TOP へリダイレクト
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent bfd8017 commit ef3d210

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
};

src/routes/_auth.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Box } from "@chakra-ui/react";
22
import { createFileRoute, Outlet } from "@tanstack/react-router";
33
import { AuthGuard } from "@/src/components/features/auths/AuthGuard";
4+
import { UnauthenticatedBoundary } from "@/src/components/features/auths/UnauthenticatedBoundary";
45
import { Header } from "@/src/components/templates/Header";
56

67
export const Route = createFileRoute("/_auth")({
@@ -10,7 +11,9 @@ export const Route = createFileRoute("/_auth")({
1011
function RouteComponent() {
1112
return (
1213
<AuthGuard>
13-
<AuthenticatedLayout />
14+
<UnauthenticatedBoundary>
15+
<AuthenticatedLayout />
16+
</UnauthenticatedBoundary>
1417
</AuthGuard>
1518
);
1619
}

0 commit comments

Comments
 (0)