* add eslint config * migrate autoLock to features * migrate teamService to features * migrate userCreationService * migrate insights services to features * migrate ProfileRepository * update imports * migrate filter segmen tests * migrate filter segment repository * migrate getBusyTimes * migrate getLocaleFromRequest * refactor csvUtils * make filename clearer * migrate getLuckyUser integration test * migrate autoLock test to features * wip * refactors * migrate useBookerUrl * migrate more * wip * Migrate eventTypeRepository * membership repository * update imports * update imports * migrate * move organization repository * update imports * update imports * wip * wip * wip * wip * wip * wip * wip * wip * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix tests * fix type checks * fix * fix * migrate * update imports * fix tests * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix
37 lines
1.2 KiB
TypeScript
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/features/profile/lib/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(await headers(), await 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);
|