/
githubmirror
/
next.js
Обзор
Документация
Войти
/
githubmirror
/
next.js
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
canary
examples/auth0/pages/api/protected-api.ts
20 строк
526 B
Boris
refactor: rename API endpoint to '/api/protected-api' for comment (#66456)
03 июн 2024, 02:38
Не верифицирован
03 июн 2024, 02:38
fd25a6a
Код
Авторство
О чём код?
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);