Skip to content

Commit

Permalink
fix: 라우터에 params로 title이 맞는지 확인 후 에러시 error 페이지로 라우팅, 현재 postDetail 데…
Browse files Browse the repository at this point in the history
…이터의 userId가 잘못들어가 있어서 추후에 res.data.author 까지 추가로 검증해야함 (#105)
  • Loading branch information
Sonseongoh committed Oct 29, 2024
1 parent 4a21d17 commit 4fefb42
Show file tree
Hide file tree
Showing 3 changed files with 4,910 additions and 3,029 deletions.
Binary file modified .yarn/install-state.gz
Binary file not shown.
9 changes: 8 additions & 1 deletion src/pages/PostDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ interface PostData {
}

const PostDetail = () => {
const { postId } = useParams<{ postId: string }>()
const { title, postId } = useParams<{ title: string; postId: string }>()
const [postData, setPostData] = useState<PostData | null>(null)
const [error, setError] = useState<string | null>(null)
const { sessionId } = useAuthStore()
Expand All @@ -34,7 +34,9 @@ const PostDetail = () => {
const handlePostEdit = () => {
navigate(`/write?id=${postId}`, { state: { postData } })
}

console.log(postData)

useEffect(() => {
const fetchPostData = async () => {
try {
Expand All @@ -44,6 +46,11 @@ const PostDetail = () => {
},
})
setPostData(res.data)
console.log(res.data)

if (res.data.title !== title) {
navigate('/error') // 에러 페이지 경로에 맞게 수정
}
} catch (err: unknown) {
if (axios.isAxiosError(err)) {
setError(err.response?.data?.message || '게시글을 가져오는 데 실패했습니다.')
Expand Down
Loading

0 comments on commit 4fefb42

Please sign in to comment.