[CAL-409] Prevents usernames with special characters (#668)

pull/648/head^2
Omar López 2021-09-17 17:08:02 -06:00 committed by GitHub
parent dd9f5fe791
commit f6005b8c70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 5 deletions

View File

@ -1,5 +1,5 @@
export const slugify = (str: string) => {
return str.replace(/\s+/g, "-").toLowerCase();
return str.replace(/[^a-zA-Z0-9-]/g, "-").toLowerCase();
};
export default slugify;

View File

@ -1,13 +1,16 @@
import prisma from "../../../lib/prisma";
import { hashPassword } from "../../../lib/auth";
import { hashPassword } from "@lib/auth";
import prisma from "@lib/prisma";
import slugify from "@lib/slugify";
import { NextApiRequest, NextApiResponse } from "next";
export default async function handler(req, res) {
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
if (req.method !== "POST") {
return;
}
const data = req.body;
const { username, email, password } = data;
const { email, password } = data;
const username = slugify(data.username);
if (!username) {
res.status(422).json({ message: "Invalid username" });