Skip to content

Commit debab0b

Browse files
committed
fix: Remove server auth session at detail post page
1 parent 8f3f9ee commit debab0b

File tree

4 files changed

+28
-12
lines changed

4 files changed

+28
-12
lines changed

src/features/post/detail/post/edit-post-button.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client'
22

3-
import { useAdminSession, useProgressBar } from '@/lib/hooks'
3+
import { useProgressBar } from '@/lib/hooks'
44
import { mainPath } from '@/lib/route'
55
import { Button } from '@/lib/ui/button'
66
import { Pencil } from 'lucide-react'
+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from './delete-post-button'
22
export * from './edit-post-button'
33
export * from './floating-menu'
4+
export * from './post-author-buttons'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use client'
2+
3+
import type { FC } from 'react'
4+
import { EditPostButton } from './edit-post-button'
5+
import { DeletePostButton } from './delete-post-button'
6+
import { useAdminSession } from '@/lib/hooks'
7+
8+
interface Props {
9+
postId: string
10+
}
11+
12+
export const PostAuthorButtons: FC<Props> = ({ postId }) => {
13+
const { isAdminAuthorized } = useAdminSession()
14+
15+
return (
16+
isAdminAuthorized && (
17+
<div className='flex gap-4'>
18+
<EditPostButton id={postId} />
19+
<DeletePostButton id={postId} />
20+
</div>
21+
)
22+
)
23+
}

src/widgets/post/detail/detail-post-widget.tsx

+3-11
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
import { DeletePostButton, EditPostButton } from '@/features/post/detail/post'
2-
import { getServerAuth } from '@/lib/auth'
1+
import type { FC } from 'react'
2+
import { PostAuthorButtons } from '@/features/post/detail/post'
33
import { Badge } from '@/lib/ui/badge'
44
import { formatDateToFull, textSanitizing } from '@/lib/utils'
55
import { Post } from '@prisma/client'
6-
import type { FC } from 'react'
76

87
interface Props {
98
post: Post
109
}
1110

1211
export const DetailPostWidget: FC<Props> = async ({ post }) => {
13-
const { isAdminAuthorized } = await getServerAuth()
14-
1512
return (
1613
<article className='flex flex-col gap-7 text-white rounded-lg pb-14'>
1714
<section className='flex flex-col gap-4 border-b border-b-slate-700 pb-7'>
@@ -34,12 +31,7 @@ export const DetailPostWidget: FC<Props> = async ({ post }) => {
3431
<div className='flex justify-between items-center h-8'>
3532
<time className='text-sm text-gray-500'>{formatDateToFull(post.createdAt)}</time>
3633

37-
{isAdminAuthorized && (
38-
<div className='flex gap-4'>
39-
<EditPostButton id={post.id} />
40-
<DeletePostButton id={post.id} />
41-
</div>
42-
)}
34+
<PostAuthorButtons postId={post.id} />
4335
</div>
4436
</div>
4537
</section>

0 commit comments

Comments
 (0)