Skip to content

Commit

Permalink
Add profanity filter to registration form (#73)
Browse files Browse the repository at this point in the history
* Add profanity filter from 'no-profanity' package to registration form
  • Loading branch information
joshuasilva414 authored Jul 27, 2024
1 parent 4039519 commit cfd3f65
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"nanoid": "^5.0.7",
"next": "14.2.5",
"next-safe-action": "^5.2.3",
"no-profanity": "^1.5.1",
"pg": "^8.12.0",
"postcss": "8.4.39",
"postgres": "^3.4.4",
Expand Down
11 changes: 8 additions & 3 deletions apps/web/src/validators/shared/RegisterForm.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import { z } from "zod";
import c from "config";
import { isProfane } from "no-profanity";

const defaultPrettyError = {
errorMap: () => ({ message: "Please select a value" }),
};

const noProfanityValidator = (val: any) => !isProfane(val);
const noProfanityMessage = "Profanity is not allowed";

export const RegisterFormValidator = z.object({
firstName: z
.string()
.min(1, { message: "Firstname must be at least one character" })
.max(50, { message: "Firstname must be less than 50 characters" }),
lastName: z

.string()
.min(1, { message: "Lastname must be at least 1 character" })
.max(50, { message: "Lastname must be less than 50 characters" }),
Expand Down Expand Up @@ -139,7 +142,8 @@ export const RegisterFormValidator = z.object({
.regex(/^[a-zA-Z0-9]+$/, {
message: "HackerTag must be alphanumeric and have no spaces",
})
.toLowerCase(),
.toLowerCase()
.refine(noProfanityValidator, noProfanityMessage),
profileDiscordName: z
.string()
.min(2, { message: "Please enter a valid Discord Username" })
Expand All @@ -148,7 +152,8 @@ export const RegisterFormValidator = z.object({
bio: z
.string()
.min(1)
.max(500, { message: "Bio must be less than 500 characters." }),
.max(500, { message: "Bio must be less than 500 characters." })
.refine(noProfanityValidator, noProfanityMessage),
skills: z.array(
z.object({
id: z.string(),
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cfd3f65

Please sign in to comment.