Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add profanity filter to registration form #73

Merged
merged 2 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading