Return defaullt username status if not on calcom

pull/11421/merge^2
Sean Brydon 2023-09-05 14:46:17 +01:00
parent 699db2f649
commit e58f945915
2 changed files with 17 additions and 2 deletions

View File

@ -33,7 +33,6 @@ async function handler(req: RequestWithUsernameStatus, res: NextApiResponse) {
ensurePostMethod(req);
throwIfSignupIsDisabled();
const { email, password, language, token, username } = parseSignupData(req.body);
await findExistingUser(username, email);
const hashedPassword = await hashPassword(password);
const customer = await createStripeCustomer({
@ -47,6 +46,8 @@ async function handler(req: RequestWithUsernameStatus, res: NextApiResponse) {
});
if (!token) {
await findExistingUser(username, email);
// Create the user
const user = await createUser({
username,
@ -107,7 +108,6 @@ async function handler(req: RequestWithUsernameStatus, res: NextApiResponse) {
return res.status(201).json({ message: "Created user" });
} catch (e) {
console.log(e);
if (e instanceof HttpError) {
return res.status(e.statusCode).json({ message: e.message });
}

View File

@ -5,6 +5,7 @@ import prisma from "@calcom/prisma";
import notEmpty from "../../../apps/website/lib/utils/notEmpty";
import { wordlist } from "../../../apps/website/lib/utils/wordlist/wordlist";
import { IS_CALCOM } from "../constants";
export type RequestWithUsernameStatus = NextApiRequest & {
usernameStatus: {
@ -47,6 +48,20 @@ const usernameHandler =
(handler: CustomNextApiHandler) =>
async (req: RequestWithUsernameStatus, res: NextApiResponse): Promise<void> => {
const username = slugify(req.body.username);
// If we're not in Calcom, we don't need to check for premium usernames
if (!IS_CALCOM) {
req.usernameStatus = {
statusCode: 200,
requestedUserName: username,
json: {
available: true,
premium: false,
message: "Username is available",
},
};
return handler(req, res);
}
const check = await usernameCheck(username);
req.usernameStatus = {