fix bug name quizzes 2
This commit is contained in:
parent
9d0c25ea3c
commit
5c73ae89b3
@ -1,6 +1,6 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { redirect } from 'next/navigation'
|
||||
import { createClient } from '@/lib/supabase/server'
|
||||
import { createClient, createAdminClient } from '@/lib/supabase/server'
|
||||
import QuizzesClient from './QuizzesClient'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
@ -8,32 +8,37 @@ export const dynamic = 'force-dynamic'
|
||||
export default async function QuizzesPage() {
|
||||
try {
|
||||
const supabase = await createClient()
|
||||
const db = supabase as any
|
||||
const db = supabase as any
|
||||
// Client admin (service_role) pour les requêtes qui butaient sur la RLS
|
||||
// en contexte SSR/Docker (auth.uid() non résolu côté PostgREST)
|
||||
const admin = createAdminClient() as any
|
||||
|
||||
const { data: { user }, error: authError } = await supabase.auth.getUser()
|
||||
if (authError || !user) redirect('/login')
|
||||
|
||||
// Requêtes parallèles — les quizzes sont récupérés séparément avec un filtre
|
||||
// explicite sur author_id pour éviter de dépendre de la RLS dans les nested selects
|
||||
const [
|
||||
{ data: categories },
|
||||
{ data: allQuizzes },
|
||||
{ count: totalQuizzes },
|
||||
{ data: sessionIds },
|
||||
] = await Promise.all([
|
||||
// Catégories + chapitres : lecture publique, client normal OK
|
||||
db
|
||||
.from('categories')
|
||||
.select('id, name, description, subchapters(id, name)')
|
||||
.order('name'),
|
||||
db
|
||||
// Quizzes : client admin pour bypasser la RLS (filtre author_id en JS)
|
||||
admin
|
||||
.from('quizzes')
|
||||
.select('id, title, updated_at, subchapter_id')
|
||||
.eq('author_id', user.id)
|
||||
.not('subchapter_id', 'is', null),
|
||||
db
|
||||
// Comptage : idem
|
||||
admin
|
||||
.from('quizzes')
|
||||
.select('id', { count: 'exact', head: true })
|
||||
.eq('author_id', user.id),
|
||||
// Sessions : client normal (RLS trainer_id OK en SSR)
|
||||
db
|
||||
.from('sessions')
|
||||
.select('id')
|
||||
|
||||
@ -1,14 +1,14 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import { Suspense } from 'react'
|
||||
import { createClient } from '@/lib/supabase/server'
|
||||
import { createClient, createAdminClient } from '@/lib/supabase/server'
|
||||
import CreateSessionClient from './CreateSessionClient'
|
||||
|
||||
export default async function CreateSessionPage() {
|
||||
const supabase = await createClient()
|
||||
const db = supabase as any
|
||||
const admin = createAdminClient() as any
|
||||
const { data: { user } } = await supabase.auth.getUser()
|
||||
|
||||
const { data: quizzes } = await db
|
||||
const { data: quizzes } = await admin
|
||||
.from('quizzes')
|
||||
.select(`id, title, questions(id), subchapter:subchapters(name, category:categories(name))`)
|
||||
.eq('author_id', user!.id)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user