import { NextResponse } from "next/server" import { requireUser } from "@/lib/authz" import { prisma } from "@/lib/prisma" /** Apps the user has connected through OAuth, for the Settings list. */ export async function GET() { const session = await requireUser() if (session instanceof NextResponse) return session const grants = await prisma.oAuthGrant.findMany({ where: { userId: session.user.id, revokedAt: null }, orderBy: { createdAt: "desc" }, select: { id: true, scopes: true, createdAt: true, lastUsedAt: true, client: { select: { clientName: true, clientUri: true } }, }, }) return NextResponse.json({ grants: grants.map((g) => ({ id: g.id, clientName: g.client.clientName, clientUri: g.client.clientUri, scopes: g.scopes, createdAt: g.createdAt, lastUsedAt: g.lastUsedAt, })), }) }