feat: allow admin to order licenses and query all partner end customers
All checks were successful
Staging Build / build (push) Successful in 2m15s
All checks were successful
Staging Build / build (push) Successful in 2m15s
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user