File size: 508 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { cookies } from 'next/headers'
import { Redirect } from './redirect'

async function isLoggedIn() {
  // sleep for 1s
  await new Promise((resolve) => setTimeout(resolve, 1000))

  const cookieData = await cookies()
  const hasSession = !!cookieData.get('logged-in')

  return hasSession
}

export default async function Layout({ children }) {
  const loggedIn = await isLoggedIn()
  console.log({ loggedIn })

  if (!loggedIn) return <Redirect />

  return <div>Protected Layout: {children}</div>
}