import type { Comment } from "../../interfaces"; import distanceToNow from "../../lib/dateRelative"; import { useAuth0 } from "@auth0/auth0-react"; type CommentListProps = { comments?: Comment[]; onDelete: (comment: Comment) => Promise; }; export default function CommentList({ comments, onDelete }: CommentListProps) { const { user } = useAuth0(); return (
{comments && comments.map((comment) => { const isAuthor = user && user.sub === comment.user.sub; const isAdmin = user && user.email === process.env.NEXT_PUBLIC_AUTH0_ADMIN_EMAIL; return (
{comment.user.name}
{comment.user.name} {(isAdmin || isAuthor) && ( )}
{comment.text}
); })}
); }