juntekim.com/stripe_to_invoice/app/api/dashboard/connections/route.ts
2026-02-07 17:02:18 +00:00

33 lines
847 B
TypeScript

import { NextResponse } from "next/server";
import { eq } from "drizzle-orm";
import { getUserFromSession } from "@/lib/auth/get-user";
import { db } from "@/lib/db";
import { stripeAccounts, xeroConnections } from "@/lib/schema";
export async function GET() {
const user = await getUserFromSession();
if (!user) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
// Get Stripe account
const stripe = await db
.select()
.from(stripeAccounts)
.where(eq(stripeAccounts.userId, user.id))
.limit(1);
// Get Xero connection
const xero = await db
.select()
.from(xeroConnections)
.where(eq(xeroConnections.userId, user.id))
.limit(1);
return NextResponse.json({
stripeAccountId: stripe[0]?.stripeAccountId ?? null,
xeroTenantId: xero[0]?.tenantId ?? null,
});
}