Skip to content

Commit 1ee8cb8

Browse files
authored
Merge pull request #69 from JECT-Study/bug/67-chat-login-route
fix: 비로그인 시 채팅 페이지 라우터 보호 (#67)
2 parents 9b9c5c5 + c619b13 commit 1ee8cb8

4 files changed

Lines changed: 32 additions & 1 deletion

File tree

src/app/art/[id]/page.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import SizeText from "@/components/archive-detail/SizeText";
1313
import { useCreateChatRoom } from "@/hooks/useCreateChatRoom";
1414
import { getArtworkDetail } from "@/services/artworks";
1515
import { normalizeImageUrl } from "@/utils/normalizeImageUrl";
16+
import { useRequireAuth } from "@/hooks/useRequireAuth";
1617

1718
function formatDate(date: string | null) {
1819
if (!date) return "-";
@@ -32,6 +33,7 @@ export default function ArtDetailPage() {
3233
const params = useParams<{ id: string }>();
3334
const artworkId = params.id;
3435
const createChatRoom = useCreateChatRoom();
36+
const { isAuthReady, isAuthenticated } = useRequireAuth("/auth");
3537
const [inquiryErrorMessage, setInquiryErrorMessage] = useState<string | null>(null);
3638

3739
const query = useQuery({
@@ -56,6 +58,8 @@ export default function ArtDetailPage() {
5658
const handleInquiryClick = () => {
5759
if (!Number.isFinite(numericArtworkId)) return;
5860

61+
if (!isAuthReady || !isAuthenticated) return;
62+
5963
setInquiryErrorMessage(null);
6064
createChatRoom.mutate(
6165
{ targetType: "ARTWORK", targetId: numericArtworkId },

src/app/auth/page.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ export default function LoginPage() {
1010
const router = useRouter();
1111

1212
const handleClose = () => {
13-
router.push("/");
13+
if (window.history.length > 1) {
14+
router.back();
15+
} else {
16+
router.push("/");
17+
}
1418
};
1519

1620
return (

src/app/chat/layout.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"use client";
2+
3+
import type { ReactNode } from "react";
4+
5+
import { useRequireAuth } from "@/hooks/useRequireAuth";
6+
7+
interface ChatLayoutProps {
8+
children: ReactNode;
9+
}
10+
11+
export default function ChatLayout({ children }: ChatLayoutProps) {
12+
const { isAuthReady, isAuthenticated } = useRequireAuth("/auth");
13+
14+
if (!isAuthReady || !isAuthenticated) {
15+
return null;
16+
}
17+
18+
return children;
19+
}

src/app/space/[id]/page.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import SizeText from "@/components/archive-detail/SizeText";
1212
import { useCreateChatRoom } from "@/hooks/useCreateChatRoom";
1313
import { getSpaceDetail } from "@/services/spaces";
1414
import { normalizeImageUrl } from "@/utils/normalizeImageUrl";
15+
import { useRequireAuth } from "@/hooks/useRequireAuth";
1516

1617
function hasText(value?: string | null) {
1718
return Boolean(value?.trim());
@@ -26,6 +27,7 @@ export default function SpaceDetailPage() {
2627
const params = useParams<{ id: string }>();
2728
const spaceId = params.id;
2829
const createChatRoom = useCreateChatRoom();
30+
const { isAuthReady, isAuthenticated } = useRequireAuth("/auth");
2931
const [inquiryErrorMessage, setInquiryErrorMessage] = useState<string | null>(null);
3032

3133
const query = useQuery({
@@ -51,6 +53,8 @@ export default function SpaceDetailPage() {
5153
const handleInquiryClick = () => {
5254
if (!Number.isFinite(numericSpaceId)) return;
5355

56+
if (!isAuthReady || !isAuthenticated) return;
57+
5458
setInquiryErrorMessage(null);
5559
createChatRoom.mutate(
5660
{ targetType: "SPACE", targetId: numericSpaceId },

0 commit comments

Comments
 (0)