react-code-dataset / next.js /test /e2e /app-dir /app-prefetch /app /prefetch-dynamic-usage /(protected) /layout.js
Download next.js/test/e2e/app-dir/app-prefetch/app/prefetch-dynamic-usage/(protected)/layout.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 508 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/test/e2e/app-dir/app-prefetch/app/prefetch-dynamic-usage/(protected)/layout.js
- Command line
-
hf download 'hf://datasets/Devendra174/react-code-dataset/next.js/test/e2e/app-dir/app-prefetch/app/prefetch-dynamic-usage/(protected)/layout.js'
-
curl -L -o layout.js 'https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/test/e2e/app-dir/app-prefetch/app/prefetch-dynamic-usage/(protected)/layout.js'
508 Bytes
| 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> | |
| } | |