Implement RPC function for user emails

This commit is contained in:
gpt-engineer-app[bot]
2025-10-30 18:03:17 +00:00
parent 3318fdaa3f
commit bcbb8019bd
3 changed files with 61 additions and 6 deletions

View File

@@ -19,6 +19,7 @@ interface UserProfile {
id: string;
user_id: string;
username: string;
email?: string;
display_name?: string;
avatar_url?: string;
banned: boolean;
@@ -49,17 +50,15 @@ export function ProfileManager() {
try {
setLoading(true);
// Fetch profiles with user roles
// Fetch profiles with emails using secure RPC function
const { data: profilesData, error: profilesError } = await supabase
.from('profiles')
.select('*')
.order('created_at', { ascending: false });
.rpc('get_users_with_emails');
if (profilesError) throw profilesError;
// Fetch roles for each user
const profilesWithRoles = await Promise.all(
profilesData.map(async (profile) => {
(profilesData || []).map(async (profile) => {
const { data: rolesData } = await supabase
.from('user_roles')
.select('role')
@@ -453,7 +452,7 @@ export function ProfileManager() {
targetUser={{
userId: deletionTarget.user_id,
username: deletionTarget.username,
email: '', // Email not available in profile data
email: deletionTarget.email || 'Email not found',
displayName: deletionTarget.display_name || undefined,
roles: deletionTarget.roles
}}