Skip to content

Commit 6580526

Browse files
committed
Sets up a column for profiles
1 parent 7f592a0 commit 6580526

File tree

2 files changed

+45
-11
lines changed

2 files changed

+45
-11
lines changed

example/next-storage/components/Account.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import styles from '../styles/Home.module.css'
66
import { AuthSession } from '../../../dist/main'
77
import { DEFAULT_AVATARS_BUCKET } from '../lib/constants'
88

9-
type Profile = {
9+
export type Profile = {
10+
id: string
1011
avatar_url: string
1112
username: string
1213
dob: string
Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,65 @@
11
import { useState, useEffect, ChangeEvent } from 'react'
22
import { supabase } from '../lib/api'
33
import Auth from '../components/Auth'
4-
import Account from '../components/Account'
5-
import Avatar from '../components/Avatar'
4+
import Account, { Profile } from '../components/Account'
65
import styles from '../styles/Home.module.css'
76
import { AuthSession } from '../../../dist/main'
8-
import { DEFAULT_AVATARS_BUCKET } from '../lib/constants'
9-
10-
type Profile = {
11-
avatar_url: string
12-
username: string
13-
dob: string
14-
}
157

168
export default function Home() {
179
const [session, setSession] = useState<AuthSession | null>(null)
10+
const [profiles, setProfiles] = useState<Profile[] | null>(null)
1811

1912
useEffect(() => {
2013
setSession(supabase.auth.session())
14+
getPublicProfiles()
15+
16+
// TODO: listen to changes in profile table
17+
// const mySubscription = supabase
18+
// .from('profiles')
19+
// .on('*', (payload) => {
20+
// console.log('Change received!', payload)
21+
// })
22+
// .subscribe()
2123

2224
supabase.auth.onAuthStateChange((_event: string, session: AuthSession | null) => {
2325
setSession(session)
2426
})
2527
}, [])
2628

29+
async function getPublicProfiles() {
30+
try {
31+
const { data, error } = await supabase
32+
.from('profiles')
33+
.select('id, username, avatar_url, dob')
34+
if (error) {
35+
throw error
36+
}
37+
console.log('data', data)
38+
setProfiles(data)
39+
} catch (error) {
40+
console.log('error', error.message)
41+
}
42+
}
43+
2744
return (
2845
<div className={styles.container}>
29-
{!session ? <Auth /> : <Account key={session.user.id} session={session} />}
46+
{!session ? (
47+
<Auth />
48+
) : (
49+
<div style={{ display: 'flex', gap: 20 }}>
50+
<div>
51+
<Account key={session.user.id} session={session} />
52+
</div>
53+
<div>
54+
{profiles?.map((profile) => (
55+
<div key={profile.id}>
56+
<p>{profile.id}</p>
57+
<p>{profile.username}</p>
58+
</div>
59+
))}
60+
</div>
61+
</div>
62+
)}
3063
</div>
3164
)
3265
}

0 commit comments

Comments
 (0)