diff --git a/shop/app/order/page.tsx b/shop/app/order/page.tsx index 0ddbc3b..4d524a1 100644 --- a/shop/app/order/page.tsx +++ b/shop/app/order/page.tsx @@ -1,4 +1,5 @@ import { createClient } from '@/lib/supabase/server' +import { createAdminClient } from '@/lib/supabase/admin' import { getProducts, getCategories } from '@/lib/actions/products' import { getEndCustomers } from '@/lib/actions/end-customers' import { OrderWizard } from '@/components/order-wizard' @@ -41,13 +42,25 @@ async function OrderDataWrapper() { .eq('id', user.id) .single() - if (userData?.role === 'admin') { - redirect('/admin/einstellungen') - } - const products = await getProducts().catch(() => []) const categories = await getCategories().catch(() => []) - const endCustomers = await getEndCustomers().catch(() => []) + + // Admin sees all end customers across partners + let endCustomers = [] + if (userData?.role === 'admin') { + try { + const adminClient = createAdminClient() + const { data } = await adminClient + .from('end_customers') + .select('*') + .order('company_name', { ascending: true }) + endCustomers = data || [] + } catch (e) { + console.error('Fehler beim Laden aller Endkunden für Admin:', e) + } + } else { + endCustomers = await getEndCustomers().catch(() => []) + } // Fetch profile safely using maybeSingle let profile = null diff --git a/shop/components/login-form.tsx b/shop/components/login-form.tsx index d38b17d..5bbfa1d 100644 --- a/shop/components/login-form.tsx +++ b/shop/components/login-form.tsx @@ -35,10 +35,12 @@ export function LoginForm({ try { const res = await signIn(email, password); - if (res.role === "admin") { + if (nextParam) { + router.push(nextParam); + } else if (res.role === "admin") { router.push("/admin/einstellungen"); } else { - router.push(nextParam || "/my-customers"); + router.push("/my-customers"); } } catch (error: unknown) { setError(error instanceof Error ? error.message : "An error occurred");