fix: resolve JSON parsing error in Stripe subscription endpoint (#23892)

* fix: resolve JSON parsing error in Stripe subscription endpoint

- Fix 'Unexpected end of JSON input' error during premium username upgrade
- Replace res.status(404).end() with proper JSON response
- Add descriptive error message for missing userId or intentUsername parameters
- Ensure consistent JSON response format across all error paths

Co-Authored-By: anik@cal.com <adhabal2002@gmail.com>

* fix: add proper session handling to Stripe subscription endpoint

- Import getServerSession from @calcom/features/auth/lib/getServerSession
- Use getServerSession({ req }) to properly populate user session
- Fix session validation that was causing 'Unexpected end of JSON input' error
- Ensure subscription endpoint handles sessions consistently with other Cal.com API endpoints

Co-Authored-By: anik@cal.com <adhabal2002@gmail.com>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
Anik Dhabal Babu
2025-09-17 15:03:16 +00:00
committed by GitHub
co-authored by anik@cal.com Devin AI
parent bb6f5cca93
commit 5bb2bc3ba4
@@ -2,6 +2,7 @@ import type { NextApiRequest, NextApiResponse } from "next";
import type Stripe from "stripe";
import { getPremiumMonthlyPlanPriceId } from "@calcom/app-store/stripepayment/lib/utils";
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
import { checkPremiumUsername } from "@calcom/features/ee/common/lib/checkPremiumUsername";
import { WEBAPP_URL } from "@calcom/lib/constants";
import prisma from "@calcom/prisma";
@@ -12,11 +13,12 @@ import stripe from "../lib/server";
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
if (req.method === "GET") {
const userId = req.session?.user.id;
const session = await getServerSession({ req });
const userId = session?.user?.id;
let { intentUsername = null } = req.query;
const { callbackUrl } = req.query;
if (!userId || !intentUsername) {
res.status(404).end();
res.status(404).json({ message: "Missing required parameters: userId or intentUsername" });
return;
}
if (intentUsername && typeof intentUsername === "object") {