MCPcopy
hub / github.com/nextauthjs/next-auth / Page

Function Page

apps/dev/pages/protected.js:5–35  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3import Layout from "../components/layout"
4
5export default function Page() {
6 const { status } = useSession({
7 required: true,
8 })
9 const [content, setContent] = useState()
10
11 // Fetch content from protected route
12 useEffect(() => {
13 if (status === "loading") return
14 const fetchData = async () => {
15 const res = await fetch("/api/examples/protected")
16 const json = await res.json()
17 if (json.content) {
18 setContent(json.content)
19 }
20 }
21 fetchData()
22 }, [status])
23
24 if (status === "loading") return <Layout>Loading...</Layout>
25
26 // If session exists, display content
27 return (
28 <Layout>
29 <h1>Protected Page</h1>
30 <p>
31 <strong>{content}</strong>
32 </p>
33 </Layout>
34 )
35}

Callers

nothing calls this directly

Calls 2

useSessionFunction · 0.90
fetchDataFunction · 0.70

Tested by

no test coverage detected