Files
archived-next-auth/apps/dev/nextjs/pages/api/examples/protected.ts
Balázs Orbán 47eec2c498 update pages
2023-04-21 11:45:05 +02:00

20 lines
544 B
TypeScript

// This is an example of to protect an API route
import { authConfig } from "../auth-old/[...nextauth]"
import { getServerSession } from "next-auth/next"
export default async (req, res) => {
const session = await getServerSession(req, res, authConfig as any)
if (session) {
res.send({
content:
"This is protected content. You can access this content because you are signed in.",
session,
})
} else {
res.send({
error: "You must be sign in to view the protected content on this page.",
})
}
}