1 parent
6e23f1533b
commit
419325db12
52 files changed
+1329
-110
No files matched your search
@@ -9,7 +9,7 @@ export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function SettingsPage() {
|
||||
const auth = await resolveAuth();
|
||||
if (auth.kind === "anonymous") redirect("/login");
|
||||
if (auth.kind === "anonymous" || auth.kind === "session_expired") redirect(auth.kind === "session_expired" ? "/login?reason=expired" : "/login");
|
||||
if (auth.kind !== "ok" || !auth.ctx.moduleEnabled) redirect("/adaptador");
|
||||
if (!canManageSpreadsheetModels(auth.ctx)) {
|
||||
return (
|
||||
|
||||
@@ -7,7 +7,7 @@ export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function OperationPage() {
|
||||
const auth = await resolveAuth();
|
||||
if (auth.kind === "anonymous") redirect("/login");
|
||||
if (auth.kind === "anonymous" || auth.kind === "session_expired") redirect(auth.kind === "session_expired" ? "/login?reason=expired" : "/login");
|
||||
if (auth.kind !== "ok" || !auth.ctx.moduleEnabled) redirect("/adaptador");
|
||||
return (
|
||||
<AppShell ctx={auth.ctx}>
|
||||
|
||||
@@ -9,7 +9,7 @@ export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function AdapterHome() {
|
||||
const auth = await resolveAuth();
|
||||
if (auth.kind === "anonymous") redirect("/login");
|
||||
if (auth.kind === "anonymous" || auth.kind === "session_expired") redirect(auth.kind === "session_expired" ? "/login?reason=expired" : "/login");
|
||||
if (auth.kind !== "ok") {
|
||||
return (
|
||||
<main className="p-8">
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export function GET() {
|
||||
return NextResponse.json({ status: "live", module: "spreadsheet-adapter" });
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { collectProductionIssues } from "@/config/env";
|
||||
import { getDb } from "@/infra/db/client";
|
||||
|
||||
export const runtime = "nodejs";
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export async function GET() {
|
||||
const checks: Record<string, "ok" | "missing" | "down"> = {
|
||||
database: "down",
|
||||
redis: process.env.REDIS_URL ? "ok" : "missing",
|
||||
storage: process.env.SUPABASE_STORAGE_BUCKET && process.env.SUPABASE_STORAGE_BUCKET !== "public" ? "ok" : "missing",
|
||||
config: collectProductionIssues(process.env).length === 0 ? "ok" : "missing",
|
||||
};
|
||||
try {
|
||||
const db = await getDb();
|
||||
await db.withService((query) => query.query("select 1 as ok"));
|
||||
checks.database = "ok";
|
||||
} catch {
|
||||
checks.database = "down";
|
||||
}
|
||||
const ready = checks.database === "ok" && (process.env.NODE_ENV !== "production" || (checks.redis === "ok" && checks.storage === "ok" && checks.config === "ok"));
|
||||
return NextResponse.json({ status: ready ? "ready" : "not_ready", checks }, { status: ready ? 200 : 503 });
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { presentError } from "@/domain/spreadsheet-adapter/error-catalog";
|
||||
import { AdapterError, isAdapterError } from "@/domain/spreadsheet-adapter/errors";
|
||||
import type { RequestContext } from "@/domain/spreadsheet-adapter/types";
|
||||
import { resolveAuth } from "@/server/auth/context";
|
||||
@@ -9,18 +10,25 @@ export const dynamic = "force-dynamic";
|
||||
|
||||
export function errorResponse(error: unknown): NextResponse {
|
||||
if (isAdapterError(error)) {
|
||||
const view = presentError(error.code);
|
||||
return NextResponse.json(
|
||||
{ error: { code: error.code, message: error.message, details: error.details ?? null } },
|
||||
{ error: { code: error.code, message: error.message, action: view.action, category: view.category, reference: error.code, details: error.details ?? null } },
|
||||
{ status: error.status },
|
||||
);
|
||||
}
|
||||
console.error("spreadsheet-adapter", error instanceof Error ? error.name : "error");
|
||||
return NextResponse.json({ error: { code: "INTERNAL", message: "Erro interno." } }, { status: 500 });
|
||||
const view = presentError("INTERNAL");
|
||||
return NextResponse.json(
|
||||
{ error: { code: "INTERNAL", message: "Erro interno.", action: view.action, category: view.category, reference: "INTERNAL" } },
|
||||
{ status: 500 },
|
||||
);
|
||||
}
|
||||
|
||||
export async function requireReady(): Promise<{ ctx: RequestContext; deps: AppDeps }> {
|
||||
const auth = await resolveAuth();
|
||||
if (auth.kind === "anonymous") throw new AdapterError("UNAUTHENTICATED", "Sessão Elo Pro necessária.", 401);
|
||||
if (auth.kind === "anonymous" || auth.kind === "session_expired") {
|
||||
throw new AdapterError("UNAUTHENTICATED", auth.kind === "session_expired" ? "Sessão expirada. Entre novamente." : "Sessão Elo Pro necessária.", 401);
|
||||
}
|
||||
if (auth.kind !== "ok") throw new AdapterError("WORKSPACE_FORBIDDEN", "Workspace não autorizado.", 403);
|
||||
const { runtimeDeps } = await import("@/server/spreadsheet-adapter/runtime");
|
||||
return { ctx: auth.ctx, deps: await runtimeDeps() };
|
||||
|
||||
+10
-3
@@ -2,14 +2,20 @@ import { redirect } from "next/navigation";
|
||||
import { DEV_IDENTITIES } from "@/dev/fixtures";
|
||||
import { resolveAuth } from "@/server/auth/context";
|
||||
import { devAuthEnabled } from "@/server/auth/dev-session";
|
||||
import { buildCentralLoginUrl, safeReturnPath } from "@/server/auth/return-to";
|
||||
import { DevLogin } from "@/components/dev-login";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
export default async function LoginPage() {
|
||||
export default async function LoginPage({ searchParams }: { searchParams: Promise<{ next?: string; reason?: string }> }) {
|
||||
const params = await searchParams;
|
||||
const auth = await resolveAuth();
|
||||
if (auth.kind === "ok") redirect("/adaptador");
|
||||
if (!devAuthEnabled() && process.env.ELO_PRO_LOGIN_URL) redirect(process.env.ELO_PRO_LOGIN_URL);
|
||||
const nextPath = safeReturnPath(params.next);
|
||||
if (auth.kind === "ok") redirect(nextPath);
|
||||
if (!devAuthEnabled() && process.env.ELO_PRO_LOGIN_URL) {
|
||||
redirect(buildCentralLoginUrl(process.env.ELO_PRO_LOGIN_URL, nextPath, process.env.ELO_PRO_APP_URL));
|
||||
}
|
||||
const expired = auth.kind === "session_expired" || params.reason === "expired";
|
||||
return (
|
||||
<main className="mx-auto max-w-xl p-8">
|
||||
<p className="text-xs font-semibold tracking-wide text-bright">ELO PRO</p>
|
||||
@@ -17,6 +23,7 @@ export default async function LoginPage() {
|
||||
<p className="mt-3 text-sm text-ink/80">
|
||||
O Adaptador não cria senha, cadastro ou sessão própria. A identidade é a do Elo Pro.
|
||||
</p>
|
||||
{expired ? <p className="mt-4 text-sm">A sessão expirou. Entre novamente pelo Elo Pro.</p> : null}
|
||||
{devAuthEnabled() ? <DevLogin identities={DEV_IDENTITIES} /> : <p className="mt-6 text-sm">Defina ELO_PRO_LOGIN_URL com o endereço do login central.</p>}
|
||||
</main>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user