Skip to content

Commit ab91b33

Browse files
committed
testing the service key working on vercel edge function
1 parent 2839cb1 commit ab91b33

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

nextjs/app/api/og/route.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)