@@ -114,31 +114,41 @@ export default function SocialPage() {
114114
115115 // --- Fetch Data ---
116116 useEffect ( ( ) => {
117- if ( ! supabase ) {
118- setIsLoading ( false ) ;
119- return ;
120- }
121-
122117 const fetchSupabaseData = async ( ) => {
123118 setIsLoading ( true ) ;
124119 try {
125- // 1. Fetch ALL stories (public feed)
126- const { data, error } = await supabase
127- . from ( "stories" )
128- . select (
120+ // 1. Fetch ALL stories via API route (bypasses RLS, uses admin client)
121+ let data : any [ ] = [ ] ;
122+ try {
123+ const res = await fetch ( "/api/stories/feed" ) ;
124+ if ( res . ok ) {
125+ const json = await res . json ( ) ;
126+ data = json . stories || [ ] ;
127+ }
128+ } catch {
129+ // API route failed — try direct Supabase as fallback
130+ }
131+
132+ // Fallback: direct Supabase query (may fail for wallet users due to RLS)
133+ if ( data . length === 0 && supabase ) {
134+ const { data : directData , error } = await supabase
135+ . from ( "stories" )
136+ . select (
137+ `
138+ id, numeric_id, title, content, created_at, likes, comments_count, shares, has_audio, audio_url, mood, tags, paywall_amount, teaser,
139+ author:users!stories_author_wallet_fkey (
140+ id, name, username, avatar, wallet_address, followers_count, badges
141+ )
129142 `
130- id, numeric_id, title, content, created_at, likes, comments_count, shares, has_audio, audio_url, mood, tags, paywall_amount, teaser,
131- author:users!stories_author_wallet_fkey (
132- id, name, username, avatar, wallet_address, followers_count, badges
133143 )
134- `
135- )
136- . order ( "created_at" , { ascending : false } ) ;
144+ . order ( "created_at" , { ascending : false } ) ;
137145
138- if ( error ) throw error ;
146+ if ( error ) throw error ;
147+ data = directData || [ ] ;
148+ }
139149
140- // 2. Filter out stories with missing authors (data integrity)
141- const validStories = ( data ?. filter ( ( s ) => s . author ) as any [ ] ) || [ ] ;
150+ // 2. Filter out stories with missing authors (data integrity) and non-public
151+ const validStories = ( data ?. filter ( ( s : any ) => s . author ) as any [ ] ) || [ ] ;
142152
143153 // 3. Collect unique author wallet addresses for follow status check
144154 const authorWallets = [
@@ -232,7 +242,7 @@ export default function SocialPage() {
232242 } ;
233243
234244 fetchSupabaseData ( ) ;
235- } , [ supabase , address ] ) ;
245+ } , [ address ] ) ;
236246
237247 // --- Event Handlers ---
238248
0 commit comments