All files / Bandstand/src/app/(band) layout.tsx

0% Statements 0/28
0% Branches 0/1
0% Functions 0/1
0% Lines 0/28

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36                                                                       
export const dynamic = 'force-dynamic'
import {ReactNode} from 'react'
import {getServerSession} from 'next-auth'
import {headers} from 'next/headers'
import {redirect} from 'next/navigation'
import {authOptions} from '@/lib/auth'
import {prisma} from '@/lib/db'
import {currentBand} from '@/lib/band'
import Tour from '@/components/tour/Tour'
import DemoStrip from '@/components/DemoStrip'
import {DEMO} from '@/lib/demo'
 
// Everything here holds copyrighted charts: band members only, and only the
// band they're looking at.
export default async function BandLayout({children}: {children: ReactNode}) {
  const session = await getServerSession(authOptions)
  const path = headers().get('x-pathname') ?? '/songs'
  if (!session?.user?.email)
    redirect('/login?callbackUrl=' + encodeURIComponent(path))
  const user = await prisma.user.findUnique({
    where: {email: session.user.email},
  })
  if (!user) redirect('/login')
  const {band} = await currentBand(user.id)
  // In several bands and none picked on this device yet
  if (!band) redirect('/bands?next=' + encodeURIComponent(path))
  return (
    <>
      {DEMO && <DemoStrip />}
      {children}
      {/* The first-time tour, until they finish or skip it */}
      <Tour auto={!user.tourDoneAt} features={{scheduling: band.scheduling}} />
    </>
  )
}