Download next.js/examples/auth0/pages/api/protected-api.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 526 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/examples/auth0/pages/api/protected-api.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/next.js/examples/auth0/pages/api/protected-api.ts
-
curl -L -o protected-api.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/next.js/examples/auth0/pages/api/protected-api.ts
526 Bytes
| import { withApiAuthRequired, getSession } from "@auth0/nextjs-auth0"; | |
| // Serverless function | |
| // Protected API, requests to '/api/protected-api' without a valid session cookie will fail | |
| async function handle(req, res) { | |
| const { user } = await getSession(req, res); | |
| try { | |
| res.status(200).json({ | |
| session: "true", | |
| id: user.sub, | |
| nickname: user.nickname, | |
| }); | |
| } catch (e) { | |
| res.status(500).json({ error: "Unable to fetch", description: e }); | |
| } | |
| } | |
| export default withApiAuthRequired(handle); | |