From f15155d31c0c9881e266d432181c00ebf9a7f45f Mon Sep 17 00:00:00 2001 From: Vishesh 'ironeagle' Bangotra Date: Tue, 18 Nov 2025 15:19:27 +0530 Subject: [PATCH] show edit button only if currentUser is present and don't updateArticle if currentUser is not present --- src/blog/components/Article/ArticleView.tsx | 10 +++++++--- src/blog/providers/Article.tsx | 4 ++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/blog/components/Article/ArticleView.tsx b/src/blog/components/Article/ArticleView.tsx index a90d3d1..4b118b3 100644 --- a/src/blog/components/Article/ArticleView.tsx +++ b/src/blog/components/Article/ArticleView.tsx @@ -6,6 +6,7 @@ import ArrowBackRoundedIcon from '@mui/icons-material/ArrowBackRounded'; import EditRoundedIcon from '@mui/icons-material/EditRounded'; import { ArticleMeta } from "../ArticleMeta"; import { ArticleProps } from '../../types/props'; +import {useAuth} from "../../providers/Author"; const ArticleContainer = styled(Box)(({ theme }) => ({ maxWidth: '800px', @@ -30,6 +31,7 @@ export default function ArticleView({ onEdit, }: ArticleProps) { + const { currentUser } = useAuth(); return ( @@ -43,9 +45,11 @@ export default function ArticleView({ sx={{ mb: 2, textTransform: 'uppercase', fontWeight: 500 }} /> - - - + {currentUser && ( + + + + )} {article.title} diff --git a/src/blog/providers/Article.tsx b/src/blog/providers/Article.tsx index 30f7e17..66ba460 100644 --- a/src/blog/providers/Article.tsx +++ b/src/blog/providers/Article.tsx @@ -66,6 +66,10 @@ export const ArticleProvider: React.FC<{ children: React.ReactNode }> = ({ child console.error('updateArticle called without _id'); return; } + if (!currentUser) { + console.error('updateArticle called without logged in user'); + return; + } const normalizedArticleData = normalizeArticleForApi(articleData); try {