import { checkAuthorizeRequest, OAuthError, type OAuthClient } from "@peppa/core"; import { redirect } from "next/navigation"; import { currentUser } from "@/lib/auth"; import { db } from "@/lib/db"; import { approve, deny } from "./actions"; import { Brand } from "@/components/Brand"; import { Button } from "@/components/ui/button"; import { Card } from "@/components/ui/card"; import { getT } from "@/lib/i18n"; export const dynamic = "force-dynamic"; type Params = Record; /** OAuth consent screen: who asks, what they get, allow / deny. */ export default async function Authorize({ searchParams }: { searchParams: Promise }) { const p = await searchParams; const user = await currentUser(); if (!user) redirect(`/login?next=${encodeURIComponent(`/oauth/authorize?${new URLSearchParams(p as Record)}`)}`); let client: OAuthClient | null = null; let error: string | null = null; try { client = await checkAuthorizeRequest(db, { clientId: p.client_id ?? "", redirectUri: p.redirect_uri ?? "", codeChallenge: p.code_challenge ?? "", codeChallengeMethod: p.code_challenge_method ?? "", responseType: p.response_type ?? "", scope: p.scope, }); } catch (e) { error = e instanceof OAuthError ? e.message : (e as Error).message; } const t = await getT(); const host = p.redirect_uri ? new URL(p.redirect_uri).host : ""; return (
{error || !client ? (

{t("Запрос авторизации некорректен: {error}", { error: t.text(error ?? "") })}

) : ( <>

{client.name} ({host}) {t("просит доступ к FORGE от имени")} {user.login}.

  • {t("видеть ваши проекты, эпики, задачи и вопросы агентов;")}
  • {t("создавать задачи и двигать карточки — перенос в «В работе» запускает агента;")}
  • {t("отвечать на вопросы агентов и принимать результат.")}

{t("Отозвать доступ можно в «Настройки → Подключённые приложения».")}

)}
); } function Hidden({ p }: { p: Params }) { return ( <> {(["client_id", "redirect_uri", "code_challenge", "code_challenge_method", "response_type", "scope", "state"] as const).map((k) => ( ))} ); }