Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,37 @@
import { redirect } from "next/navigation";
"use client";

import { useEffect } from "react";
import { useRouter } from "next/navigation";
import { useAuth } from "@/lib/auth-context";

export default function RootPage() {
// Pure Optimistic: 일단 /home으로 이동
// localStorage에 세션이 있으면 정상 렌더링
// 세션 없으면 API 호출 시 401 → 자동으로 /auth로 리다이렉트
redirect("/home");
const { isAuthenticated, isLoading } = useAuth();
const router = useRouter();

useEffect(() => {
if (isLoading) {
return;
}

// Pure Optimistic: 인증 상태에 따라 리디렉트
// localStorage에 세션이 있으면 /home으로
// 세션 없으면 /auth로
if (isAuthenticated) {
router.push("/home");
} else {
router.push("/auth");
}
}, [isAuthenticated, isLoading, router]);

// 로딩 중
return (
<div className="flex min-h-screen items-center justify-center bg-background">
<div className="w-full max-w-md space-y-8 px-4 text-center">
<h1 className="text-heading-1 font-bold text-foreground">로딩 중...</h1>
<p className="text-body-2 text-muted-foreground">
잠시만 기다려주세요.
</p>
</div>
</div>
);
}
Loading