|
| 1 | +import { createClient } from '@/lib/supabase/server'; |
| 2 | + |
| 3 | +export const dynamic = 'force-dynamic'; |
| 4 | +export const revalidate = 0; |
| 5 | + |
| 6 | +export default async function DiagnosticPage() { |
| 7 | + const supabase = await createClient(); |
| 8 | + |
| 9 | + // Get current user |
| 10 | + const { data: { user } } = await supabase.auth.getUser(); |
| 11 | + |
| 12 | + // Try to fetch ALL posts (bypassing published filter temporarily) |
| 13 | + const { data: allPosts, error: allError } = await supabase |
| 14 | + .from('posts') |
| 15 | + .select('id, title, published, published_at, author_id, created_at') |
| 16 | + .order('created_at', { ascending: false }) |
| 17 | + .limit(10); |
| 18 | + |
| 19 | + // Try to fetch only published posts |
| 20 | + const { data: publishedPosts, error: pubError } = await supabase |
| 21 | + .from('posts') |
| 22 | + .select('id, title, published, published_at, author_id') |
| 23 | + .eq('published', true) |
| 24 | + .order('published_at', { ascending: false }) |
| 25 | + .limit(10); |
| 26 | + |
| 27 | + return ( |
| 28 | + <div className="min-h-screen bg-white dark:bg-gray-900 p-8 pt-24"> |
| 29 | + <div className="max-w-4xl mx-auto"> |
| 30 | + <h1 className="text-3xl font-bold mb-8">Database Diagnostic</h1> |
| 31 | + |
| 32 | + <div className="mb-8 p-4 bg-gray-100 dark:bg-gray-800 rounded"> |
| 33 | + <h2 className="text-xl font-semibold mb-2">Current User</h2> |
| 34 | + <pre className="text-sm overflow-auto"> |
| 35 | + {JSON.stringify({ userId: user?.id, email: user?.email }, null, 2)} |
| 36 | + </pre> |
| 37 | + </div> |
| 38 | + |
| 39 | + <div className="mb-8 p-4 bg-gray-100 dark:bg-gray-800 rounded"> |
| 40 | + <h2 className="text-xl font-semibold mb-2">All Posts Query (Recent 10)</h2> |
| 41 | + {allError && ( |
| 42 | + <div className="text-red-600 mb-2">Error: {allError.message}</div> |
| 43 | + )} |
| 44 | + <pre className="text-sm overflow-auto max-h-96"> |
| 45 | + {JSON.stringify(allPosts, null, 2)} |
| 46 | + </pre> |
| 47 | + </div> |
| 48 | + |
| 49 | + <div className="mb-8 p-4 bg-gray-100 dark:bg-gray-800 rounded"> |
| 50 | + <h2 className="text-xl font-semibold mb-2">Published Posts Query</h2> |
| 51 | + {pubError && ( |
| 52 | + <div className="text-red-600 mb-2">Error: {pubError.message}</div> |
| 53 | + )} |
| 54 | + <pre className="text-sm overflow-auto max-h-96"> |
| 55 | + {JSON.stringify(publishedPosts, null, 2)} |
| 56 | + </pre> |
| 57 | + <div className="mt-4 text-sm"> |
| 58 | + <strong>Count:</strong> {publishedPosts?.length || 0} |
| 59 | + </div> |
| 60 | + </div> |
| 61 | + |
| 62 | + <div className="p-4 bg-blue-50 dark:bg-blue-900 rounded"> |
| 63 | + <h3 className="font-semibold mb-2">What to check:</h3> |
| 64 | + <ul className="list-disc list-inside text-sm space-y-1"> |
| 65 | + <li>Do posts exist in "All Posts"?</li> |
| 66 | + <li>Are any posts showing `published: true`?</li> |
| 67 | + <li>Do published posts have a `published_at` timestamp?</li> |
| 68 | + <li>Does "Published Posts Query" return any results?</li> |
| 69 | + <li>Are there any error messages?</li> |
| 70 | + </ul> |
| 71 | + </div> |
| 72 | + </div> |
| 73 | + </div> |
| 74 | + ); |
| 75 | +} |
0 commit comments