Skip to content

Commit 01f8164

Browse files
fix(courses): use admin client for teacher course pages to fix RLS mismatch
The JWT's tenant_id claim (from app_metadata) doesn't match the actual subdomain tenant ID. RLS get_tenant_id() reads JWT claims, so queries return empty results even for valid courses. The middleware sets the correct tenant ID via x-tenant-id header (getCurrentTenantId()), but RLS can't use that. Fix: use createAdminClient() for course detail page queries with manual tenant_id filtering from the header. Auth is validated via getCurrentUserId(). Ownership check remains on author_id. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent d8850c2 commit 01f8164

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

  • app/[locale]/dashboard/teacher/courses/[courseId]

app/[locale]/dashboard/teacher/courses/[courseId]/page.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createClient } from '@/lib/supabase/server'
1+
import { createAdminClient } from '@/lib/supabase/admin'
22
import { redirect, notFound } from 'next/navigation'
33
import Link from 'next/link'
44
import { getTranslations } from 'next-intl/server'
@@ -33,7 +33,7 @@ interface PageProps {
3333

3434
export default async function CourseManagementPage({ params }: PageProps) {
3535
const { courseId } = await params
36-
const supabase = await createClient()
36+
const supabase = createAdminClient()
3737
const t = await getTranslations('dashboard.teacher.manageCourse')
3838
const tenantId = await getCurrentTenantId()
3939

@@ -42,7 +42,8 @@ export default async function CourseManagementPage({ params }: PageProps) {
4242
redirect('/auth/login')
4343
}
4444

45-
// Get course and verify ownership
45+
// Use admin client — RLS get_tenant_id() reads JWT claims which may not match
46+
// the actual subdomain tenant. We validate tenant ownership manually.
4647
const { data: course, error: courseError } = await supabase
4748
.from('courses')
4849
.select('*')

0 commit comments

Comments
 (0)