feat: restrict order creation to users assigned to a company
All checks were successful
Staging Build / build (push) Successful in 3m31s

This commit is contained in:
DanielS
2026-07-04 15:33:44 +02:00
parent 5f65f890ee
commit 149eae59c9
2 changed files with 34 additions and 3 deletions

View File

@@ -40,13 +40,28 @@ async function OrderDataWrapper({ orderId }: { orderId?: string }) {
redirect(`/auth/login?next=/order${orderId ? `?id=${orderId}` : ''}`)
}
// Check user role
// Check user role and company
const { data: userData } = await supabase
.from('users')
.select('role')
.select('role, company_id')
.eq('id', user.id)
.single()
const isAdmin = userData?.role === 'admin'
const hasCompany = !!userData?.company_id
if (!isAdmin && !hasCompany) {
return (
<div className="max-w-md mx-auto mt-12 p-6 bg-red-500/10 border border-red-500/20 rounded-2xl text-center space-y-4">
<h2 className="text-xl font-bold text-red-400">Kein Unternehmen zugewiesen</h2>
<p className="text-slate-400 text-sm">
Sie müssen einem Unternehmen zugewiesen sein, um Anfragen erstellen zu können.
Bitte wenden Sie sich an den Administrator.
</p>
</div>
)
}
let initialOrder = null
if (orderId) {
const adminClient = createAdminClient()