fixes for public listed articles
This commit is contained in:
@@ -18,15 +18,8 @@ export const ArticleProvider: React.FC<{ children: React.ReactNode }> = ({ child
|
||||
setLoading(true);
|
||||
setError(null);
|
||||
|
||||
const res = await api.get<ArticleModel[]>('/articles', {
|
||||
params: { skip: 0, limit: 10 },
|
||||
});
|
||||
|
||||
const formatted = res.data.map((a) => ({
|
||||
...a,
|
||||
id: a._id || undefined,
|
||||
}));
|
||||
|
||||
const res = await api.get<ArticleModel[]>('/articles', { params: { skip: 0, limit: 10 } });
|
||||
const formatted = res.data.map((a) => ({ ...a, id: a._id || undefined }));
|
||||
setArticles(formatted);
|
||||
} catch (err: any) {
|
||||
console.error('Failed to fetch articles:', err);
|
||||
@@ -38,7 +31,13 @@ export const ArticleProvider: React.FC<{ children: React.ReactNode }> = ({ child
|
||||
|
||||
/** 🔹 Auto-fetch articles whenever user logs in/out */
|
||||
useEffect(() => {
|
||||
if (token) fetchArticles();
|
||||
// Always load once on mount
|
||||
// If endpoint requires JWT, fallback safely
|
||||
if (!token) {
|
||||
fetchArticles().catch(() => setLoading(false)); // try anyway (handles both public/protected)
|
||||
} else {
|
||||
fetchArticles();
|
||||
}
|
||||
}, [token]);
|
||||
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user