11import { createClient } from "@/lib/supabase/server" ;
2- import { createAdminClient } from "@/lib/supabase/admin" ;
32import { Button } from "@/components/ui/button" ;
43import Link from "next/link" ;
54import { notFound } from "next/navigation" ;
@@ -23,7 +22,7 @@ import {
2322} from "@/components/ui/accordion" ;
2423import { Card , CardContent } from "@/components/ui/card" ;
2524import { getTranslations } from 'next-intl/server' ;
26- import { getCurrentUserId , getCurrentTenantId } from '@/lib/supabase/tenant'
25+ import { getCurrentUserId } from '@/lib/supabase/tenant'
2726
2827export const dynamic = 'force-dynamic' ;
2928
@@ -37,14 +36,11 @@ interface Lesson {
3736export default async function CourseDetailsPage ( props : { params : Promise < { id : string } > } ) {
3837 const params = await props . params ;
3938 const t = await getTranslations ( 'coursePublicDetails' ) ;
40- const tenantId = await getCurrentTenantId ( ) ;
41- // Use admin client for public reads — anon JWT has no tenant_id claim,
42- // so RLS get_tenant_id() defaults to wrong tenant for non-default tenants.
43- const adminClient = createAdminClient ( ) ;
39+ const supabase = await createClient ( ) ;
4440
4541 const userId = await getCurrentUserId ( )
4642 // Fetch course with lessons and category
47- const { data : course , error } = await adminClient
43+ const { data : course , error } = await supabase
4844 . from ( "courses" )
4945 . select ( `
5046 *,
@@ -61,7 +57,6 @@ export default async function CourseDetailsPage(props: { params: Promise<{ id: s
6157 ` )
6258 . eq ( "course_id" , parseInt ( params . id ) )
6359 . eq ( "status" , "published" )
64- . eq ( "tenant_id" , tenantId )
6560 . single ( ) ;
6661
6762 if ( error || ! course ) {
@@ -71,7 +66,7 @@ export default async function CourseDetailsPage(props: { params: Promise<{ id: s
7166 // Fetch author separately (profiles is global, no tenant_id)
7267 let author = null ;
7368 if ( course . author_id ) {
74- const { data : authorData } = await adminClient
69+ const { data : authorData } = await supabase
7570 . from ( "profiles" )
7671 . select ( "id, full_name, avatar_url, bio" )
7772 . eq ( "id" , course . author_id )
@@ -85,10 +80,9 @@ export default async function CourseDetailsPage(props: { params: Promise<{ id: s
8580 const estimatedHours = Math . floor ( totalLessons * 10 / 60 ) ;
8681 const estimatedMinutes = ( totalLessons * 10 ) % 60 ;
8782
88- // Check user's enrollment (uses RLS client — only works for logged-in users)
83+ // Check user's enrollment
8984 let hasAccess = false ;
9085 if ( userId ) {
91- const supabase = await createClient ( ) ;
9286 const { data : enrollment } = await supabase
9387 . from ( 'enrollments' )
9488 . select ( 'enrollment_id' )
@@ -103,7 +97,7 @@ export default async function CourseDetailsPage(props: { params: Promise<{ id: s
10397 }
10498
10599 // Fetch product for pricing
106- const { data : productCourses } = await adminClient
100+ const { data : productCourses } = await supabase
107101 . from ( 'product_courses' )
108102 . select ( 'product:products(*)' )
109103 . eq ( 'course_id' , parseInt ( params . id ) )
0 commit comments