mirror of
https://github.com/SrIzan10/next-auth.git
synced 2026-05-01 10:55:20 +00:00
* chore: convert to monorepo * Remove eslint, typescript, semantic-release * Add yarn.lock * Add turbo * Run test command * Move to src * Add a seperate tsconfig file * Update .gitignore * Update commands to yarn * Replace semantic-release with changesets * Update changesets usage * Fix commands: dev, setup, clean * Add back changes from main * Fixed HMR * Update .gitignore
36 lines
833 B
JavaScript
36 lines
833 B
JavaScript
import { useState, useEffect } from "react"
|
|
import { useSession } from "next-auth/react"
|
|
import Layout from "../components/layout"
|
|
|
|
export default function Page() {
|
|
const { status } = useSession({
|
|
required: true,
|
|
})
|
|
const [content, setContent] = useState()
|
|
|
|
// Fetch content from protected route
|
|
useEffect(() => {
|
|
if (status === "loading") return
|
|
const fetchData = async () => {
|
|
const res = await fetch("/api/examples/protected")
|
|
const json = await res.json()
|
|
if (json.content) {
|
|
setContent(json.content)
|
|
}
|
|
}
|
|
fetchData()
|
|
}, [status])
|
|
|
|
if (status === "loading") return <Layout>Loading...</Layout>
|
|
|
|
// If session exists, display content
|
|
return (
|
|
<Layout>
|
|
<h1>Protected Page</h1>
|
|
<p>
|
|
<strong>{content}</strong>
|
|
</p>
|
|
</Layout>
|
|
)
|
|
}
|