1
1
import ProfileCard from '../components/ProfileCard'
2
2
import { Profile } from '../lib/constants'
3
- import { Subscription , SupabaseRealtimePayload } from '@supabase/supabase-js'
3
+ import { SupabaseRealtimePayload } from '@supabase/supabase-js'
4
4
import { supabase } from '../lib/api'
5
5
import { useState , useEffect } from 'react'
6
6
7
- var realtimeProfiles : Subscription | null = null
8
-
9
7
export default function ProfileList ( ) {
10
8
const [ profiles , setProfiles ] = useState < Profile [ ] > ( [ ] )
11
9
12
10
useEffect ( ( ) => {
13
11
// getPublicProfiles()
14
12
getUserProfile ( )
15
13
16
- realtimeProfiles = supabase
17
- . from ( 'profiles' )
18
- . on ( '*' , ( payload : SupabaseRealtimePayload < Profile > ) => profileUpdated ( profiles , payload . new ) )
14
+ const realtimeProfiles = supabase
15
+ . channel ( 'profiles-channel' )
16
+ . on (
17
+ 'realtime' ,
18
+ { event : '*' , schema : 'public' , table : 'profiles' } ,
19
+ ( payload : SupabaseRealtimePayload < Profile > ) => profileUpdated ( profiles , payload . new )
20
+ )
19
21
. subscribe ( )
20
22
21
23
return ( ) => {
22
- if ( realtimeProfiles ) supabase . removeSubscription ( realtimeProfiles )
24
+ if ( realtimeProfiles ) supabase . removeChannel ( realtimeProfiles )
23
25
}
24
26
} , [ ] )
25
27
@@ -29,12 +31,12 @@ export default function ProfileList() {
29
31
}
30
32
31
33
async function getUserProfile ( ) {
32
- const user = supabase . auth . user ( )
34
+ const { user } = await supabase . auth . getUser ( )
33
35
try {
34
36
const { data, error } = await supabase
35
37
. from ( 'profiles' )
36
38
. select ( 'id, username, avatar_url, website, updated_at' )
37
- . eq ( 'id' , user . id )
39
+ . eq ( 'id' , user ? .id )
38
40
. order ( 'updated_at' , { ascending : false } )
39
41
if ( error ) {
40
42
throw error
0 commit comments