diff --git a/shop/lib/actions/users.ts b/shop/lib/actions/users.ts index a952eab..e7a367a 100644 --- a/shop/lib/actions/users.ts +++ b/shop/lib/actions/users.ts @@ -15,11 +15,11 @@ export async function getUsers() { const userMap: Record = {}; if (!dbError && dbUsers) { - dbUsers.forEach((u) => { + dbUsers.forEach((u: any) => { userMap[u.id] = { role: u.role, company_id: u.company_id || null, - company_name: u.companies?.[0]?.name || null, + company_name: Array.isArray(u.companies) ? u.companies[0]?.name || null : u.companies?.name || null, }; }); } @@ -32,7 +32,7 @@ export async function getUsers() { })); } -export async function createUser(data: { email: string; password?: string; role?: 'admin' | 'partner'; email_confirm?: boolean }) { +export async function createUser(data: { email: string; password?: string; role?: 'admin' | 'partner'; email_confirm?: boolean; company_id?: string }) { const admin = createAdminClient(); const { data: { user }, error } = await admin.auth.admin.createUser({ email: data.email, @@ -45,7 +45,7 @@ export async function createUser(data: { email: string; password?: string; role? const role = data.role || 'partner'; const { error: dbError } = await admin .from('users') - .upsert({ id: user.id, role }, { onConflict: 'id' }); + .upsert({ id: user.id, role, company_id: data.company_id || null }, { onConflict: 'id' }); if (dbError) throw dbError; revalidatePath('/admin/users'); @@ -84,7 +84,8 @@ export async function resetPassword(email: string) { email, }); if (error) throw error; - const resetLink = (data as any)?.action_link || (data as any)?.link || ''; + const linkData = data as any; + const resetLink = linkData?.properties?.action_link || linkData?.action_link || linkData?.link || ''; if (!resetLink) throw new Error('Reset link not generated'); await sendMail({ to: email, @@ -106,15 +107,15 @@ export async function getPartners() { if (dbError) throw dbError; const userMap: Record = {}; - dbUsers.forEach((u) => { + dbUsers.forEach((u: any) => { userMap[u.id] = { role: u.role, company_id: u.company_id || null, - company_name: u.companies?.[0]?.name || null, + company_name: Array.isArray(u.companies) ? u.companies[0]?.name || null : u.companies?.name || null, }; }); - const partnerIds = new Set(dbUsers.map((u) => u.id)); + const partnerIds = new Set(dbUsers.map((u: any) => u.id)); return users .filter((u) => partnerIds.has(u.id)) .map((u) => ({