
* Makes userRequired middleware * Prevent users from changing usernames to premium ones * refactor on zomars' branch (#801) * rename `profile` -> `mutation` * `createProtectedRouter()` helper * move profile mutation to `viewer.` * simplify checkUsername * Auto scrolls to error when there is one * Renames username helpers * Follows db convention Co-authored-by: Alex Johansson <alexander@n1s.se> Co-authored-by: Bailey Pumfleet <pumfleet@hey.com>
25 lines
583 B
TypeScript
25 lines
583 B
TypeScript
import slugify from "@lib/slugify";
|
|
|
|
export async function checkPremiumUsername(_username: string) {
|
|
const username = slugify(_username);
|
|
const response = await fetch("https://cal.com/api/username", {
|
|
credentials: "include",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify({ username }),
|
|
method: "POST",
|
|
mode: "cors",
|
|
});
|
|
|
|
if (response.ok) {
|
|
return {
|
|
available: true as const,
|
|
};
|
|
}
|
|
const json = await response.json();
|
|
return {
|
|
available: false as const,
|
|
message: json.message as string,
|
|
};
|
|
}
|