Files
calendar/apps/web/app/api/username/route.ts
T
Benny JooandGitHub 87bc8d649a feat: add sentry report wrapper to every api route in appDir (#19966)
* update oauth tests

* fix parseRequestData

* add logging

* add fallback

* use ??

* updates

* use parseUrlFormData in saml/callback

* update tests

* fix

* remove log

* update

* any -> unknown

* use HttpErrors

* addressed

* unknown -> any

* feat: Add entry report wrapper to every api route in appDir

* fix

* fix unit test

* fix
2025-03-11 23:38:49 -04:00

37 lines
1.2 KiB
TypeScript

import { defaultResponderForAppDir } from "app/api/defaultResponderForAppDir";
import { cookies, headers } from "next/headers";
import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";
import { z } from "zod";
import { orgDomainConfig } from "@calcom/features/ee/organizations/lib/orgDomains";
import { checkUsername } from "@calcom/lib/server/checkUsername";
import { buildLegacyRequest } from "@lib/buildLegacyCtx";
const bodySchema = z.object({
username: z.string(),
orgSlug: z.string().optional(),
});
async function postHandler(request: NextRequest) {
try {
const body = await request.json();
const { username, orgSlug } = bodySchema.parse(body);
const legacyReq = buildLegacyRequest(headers(), cookies());
// Get current org domain from request headers
const { currentOrgDomain } = orgDomainConfig(legacyReq);
const result = await checkUsername(username, currentOrgDomain || orgSlug);
return NextResponse.json(result);
} catch (error) {
console.error(error);
return NextResponse.json({ error: "Failed to check username availability" }, { status: 400 });
}
}
export const POST = defaultResponderForAppDir(postHandler);