File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed
Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -112,13 +112,25 @@ async function getUserName(userId: string | null): Promise<string | null> {
112112
113113 try {
114114 const supabase = createAdminClient ( ) ;
115- const { data } = await supabase
115+
116+ // First try public.users table
117+ const { data : userData } = await supabase
116118 . from ( 'users' )
117119 . select ( 'full_name' )
118120 . eq ( 'id' , userId )
119121 . single ( ) ;
120122
121- return data ?. full_name || null ;
123+ if ( userData ?. full_name ) {
124+ return userData . full_name ;
125+ }
126+
127+ // Fallback to auth.users metadata (requires service role)
128+ const { data : authData } = await supabase . auth . admin . getUserById ( userId ) ;
129+ return (
130+ authData ?. user ?. user_metadata ?. full_name ||
131+ authData ?. user ?. user_metadata ?. name ||
132+ null
133+ ) ;
122134 } catch {
123135 return null ;
124136 }
You can’t perform that action at this time.
0 commit comments