cal/packages/lib/fetchUsername.ts
Hariom Balhara 4b16860d07
fix: Correctly prefill username in case of non-org email invite in an org (#12854)
* fix: Correctly prefill username in case of non-org email invite in an org

* Update test

---------

Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
2023-12-19 02:44:48 +00:00

23 lines
565 B
TypeScript

type ResponseUsernameApi = {
available: boolean;
premium: boolean;
message?: string;
suggestion?: string;
};
export async function fetchUsername(username: string, orgSlug: string | null) {
const response = await fetch("/api/username", {
credentials: "include",
method: "POST",
body: JSON.stringify({
username: username.trim(),
orgSlug: orgSlug ?? undefined,
}),
headers: {
"Content-Type": "application/json",
},
});
const data = (await response.json()) as ResponseUsernameApi;
return { response, data };
}