Skip to content

Commit 46405ff

Browse files
committed
fix: userId undefined 방지
1 parent 12cae6f commit 46405ff

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

apps/next-client/src/app/community/[id]/edit/page.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
'use client';
2-
31
import React, { Suspense } from 'react';
4-
import { useSession } from 'next-auth/react';
2+
import { getServerSession } from 'next-auth';
53
import '@/styles/pages/community/community.scss';
64
import ErrorBoundary from '@/components/common/ErrorBoundary';
75
import LoadingSpinner from '@/components/common/LoadingSpinner';
86
import EditPostContent from '@/components/community/EditPostContent';
7+
import { authOptions } from '@/app/auth/authOptions';
98
import { ERROR_MESSAGES } from '@/constants/errors';
109

11-
export default function EditPostPage({ params }: { params: { id: string } }) {
12-
const { data: session } = useSession();
13-
const userId = session?.user?.id;
14-
15-
if (!userId) {
10+
export default async function EditPostPage({ params }: { params: { id: string } }) {
11+
const session = await getServerSession(authOptions);
12+
13+
if (!session?.user?.id) {
1614
throw new Error(ERROR_MESSAGES.LOGIN_REQUIRED);
1715
}
16+
17+
const userId = session.user.id;
1818

1919
return (
2020
<ErrorBoundary>

apps/next-client/src/hooks/queries/usePostEdit.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import { ALERT_MESSAGES } from '@/constants/alertMessage';
77
import { ERROR_MESSAGES } from '@/constants/errors';
88

99
// 게시글 데이터 가져오기
10-
export function usePostEditData(id: string, userId: string | undefined) {
10+
export function usePostEditData(id: string, userId: string) {
1111
const router = useRouter();
1212

1313
return useSuspenseQuery({
14-
queryKey: ['post-edit', id],
14+
queryKey: ['post-edit', id, userId],
1515
queryFn: async () => {
1616
const response = await axiosInstance.get(`${API_URLS.POSTS}/${id}`);
1717
const post = response.data;
@@ -86,7 +86,7 @@ export function useDeletePost(id: string) {
8686
});
8787
}
8888

89-
export const usePostEdit = (id: string, userId: string | undefined) => {
89+
export const usePostEdit = (id: string, userId: string) => {
9090
const [title, setTitle] = useState('');
9191
const [content, setContent] = useState('');
9292

0 commit comments

Comments
 (0)