Skip to content

Commit 730dab5

Browse files
Revert "fix(public): use admin client for public course pages on non-default tenants"
This reverts commit 031b5da.
1 parent 1bbbe7e commit 730dab5

2 files changed

Lines changed: 8 additions & 16 deletions

File tree

app/[locale]/(public)/courses/[id]/page.tsx

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { createClient } from "@/lib/supabase/server";
2-
import { createAdminClient } from "@/lib/supabase/admin";
32
import { Button } from "@/components/ui/button";
43
import Link from "next/link";
54
import { notFound } from "next/navigation";
@@ -23,7 +22,7 @@ import {
2322
} from "@/components/ui/accordion";
2423
import { Card, CardContent } from "@/components/ui/card";
2524
import { getTranslations } from 'next-intl/server';
26-
import { getCurrentUserId, getCurrentTenantId } from '@/lib/supabase/tenant'
25+
import { getCurrentUserId } from '@/lib/supabase/tenant'
2726

2827
export const dynamic = 'force-dynamic';
2928

@@ -37,14 +36,11 @@ interface Lesson {
3736
export 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))

app/[locale]/(public)/courses/page.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createAdminClient } from "@/lib/supabase/admin";
1+
import { createClient } from "@/lib/supabase/server";
22
import { getCurrentTenantId } from "@/lib/supabase/tenant";
33
import { CourseCard } from "@/components/public/course-card";
44
import { CourseSearchBar } from "@/components/shared/course-search-bar";
@@ -15,9 +15,7 @@ export default async function CoursesPage({
1515
const { search, category } = await searchParams;
1616
const t = await getTranslations('coursesCatalog');
1717
const tSearch = await getTranslations('courseSearch');
18-
// Use admin client for public reads — anon JWT has no tenant_id claim,
19-
// so RLS get_tenant_id() defaults to wrong tenant for non-default tenants.
20-
const supabase = createAdminClient();
18+
const supabase = await createClient();
2119
const tenantId = await getCurrentTenantId();
2220

2321
// Sanitize search input — strip special characters used in ilike patterns

0 commit comments

Comments
 (0)