refactor: remove edge compatibility

This commit is contained in:
Henry
2025-05-15 22:27:03 +01:00
parent 66de4b6c42
commit d065ae73e1
11 changed files with 108 additions and 167 deletions

View File

@@ -1,29 +1,23 @@
import type { NextRequest } from "next/server";
import type { NextApiRequest, NextApiResponse } from "next";
import { createNextApiContext } from "@kan/api/trpc";
import { createStripeClient } from "@kan/stripe";
export default async function handler(req: NextRequest) {
export default async function handler(
req: NextApiRequest,
res: NextApiResponse,
) {
const stripe = createStripeClient();
if (req.method !== "POST") {
return new Response(JSON.stringify({ error: "Method not allowed" }), {
status: 405,
headers: { "Content-Type": "application/json" },
});
return res.status(405).json({ error: "Method not allowed" });
}
try {
const { user } = await createNextApiContext(req);
if (!user?.stripeCustomerId) {
return new Response(
JSON.stringify({ error: "No billing account found" }),
{
status: 404,
headers: { "Content-Type": "application/json" },
},
);
return res.status(404).json({ error: "No billing account found" });
}
const session = await stripe.billingPortal.sessions.create({
@@ -31,22 +25,9 @@ export default async function handler(req: NextRequest) {
return_url: `${process.env.WEBSITE_URL}/settings`,
});
return new Response(JSON.stringify({ url: session.url }), {
status: 200,
headers: { "Content-Type": "application/json" },
});
return res.status(200).json({ url: session.url });
} catch (error) {
console.error("Error:", error);
return new Response(
JSON.stringify({ error: "Error creating portal session" }),
{
status: 500,
headers: { "Content-Type": "application/json" },
},
);
return res.status(500).json({ error: "Error creating portal session" });
}
}
export const runtime = "edge";
export const preferredRegion = "lhr1";
export const dynamic = "force-dynamic";