Skip to content

Commit

Permalink
Add backend validation
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlBest authored Mar 12, 2024
1 parent 44f6811 commit d0fca7a
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/routes/(admin)/account/api/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,20 +203,30 @@ export const actions = {
const website = formData.get("website") as string

let validationError
const fieldMaxTextLength = 50
const errorFields = []
if (!fullName) {
validationError = "Name is required"
errorFields.push("fullName")
} else if (fullName.length > fieldMaxTextLength) {
validationError = `Name must be less than ${fieldMaxTextLength} charaters`
errorFields.push("fullName")
}
if (!companyName) {
validationError =
"Company name is required. If this is a hobby project or personal app, please put your name."
errorFields.push("companyName")
} else if (companyName.length > fieldMaxTextLength) {
validationError = `Company name must be less than ${fieldMaxTextLength} charaters`
errorFields.push("companyName")
}
if (!website) {
validationError =
"Company website is required. An app store URL is a good alternative if you don't have a website."
errorFields.push("website")
} else if (website.length > fieldMaxTextLength) {
validationError = `Company website must be less than ${fieldMaxTextLength} charaters`
errorFields.push("website")
}
if (validationError) {
return fail(400, {
Expand Down

0 comments on commit d0fca7a

Please sign in to comment.