[CAL-409] Prevents usernames with special characters (#668)
This commit is contained in:
parent
dd9f5fe791
commit
f6005b8c70
2 changed files with 8 additions and 5 deletions
|
@ -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;
|
||||
|
|
|
@ -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" });
|
||||
|
|
Loading…
Reference in a new issue