fix: clean users.ts rewrite, add company_id to createUser, fix resetPassword link
All checks were successful
Staging Build / build (push) Successful in 2m38s

This commit is contained in:
DanielS
2026-06-25 00:20:18 +02:00
parent 410289a519
commit cebf677758

View File

@@ -15,11 +15,11 @@ export async function getUsers() {
const userMap: Record<string, { role: string; company_id: string | null; company_name: string | null }> = {};
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<string, { role: string; company_id: string | null; company_name: string | null }> = {};
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) => ({