34 lines
914 B
TypeScript
34 lines
914 B
TypeScript
import { NextResponse } from "next/server";
|
|
import { getServerSession } from "next-auth";
|
|
import { authOptions } from "../../../../lib/auth";
|
|
import { prisma } from "../../../../lib/prisma";
|
|
|
|
export async function GET() {
|
|
try {
|
|
const session = await getServerSession(authOptions);
|
|
if (!session?.user?.email) {
|
|
return NextResponse.json({ error: "Unauthorized." }, { status: 401 });
|
|
}
|
|
|
|
const user = await prisma.user.findUnique({
|
|
where: { email: session.user.email },
|
|
include: { store: true },
|
|
});
|
|
|
|
if (!user?.store) {
|
|
return NextResponse.json({ error: "Store not found." }, { status: 404 });
|
|
}
|
|
|
|
return NextResponse.json({
|
|
slug: user.store.slug,
|
|
stripeAccountId: user.store.stripeAccountId,
|
|
});
|
|
} catch (err: any) {
|
|
return NextResponse.json(
|
|
{ error: err?.message || "Failed to load store." },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|
|
|