Skip to content

fix: align frontend auth validation with backend#530

Merged
mehul-m-prajapati merged 2 commits into
GitMetricsLab:mainfrom
Tanish-Solanki:fix-auth-validation-mismatch
May 29, 2026
Merged

fix: align frontend auth validation with backend#530
mehul-m-prajapati merged 2 commits into
GitMetricsLab:mainfrom
Tanish-Solanki:fix-auth-validation-mismatch

Conversation

@Tanish-Solanki
Copy link
Copy Markdown
Contributor

@Tanish-Solanki Tanish-Solanki commented May 26, 2026

Related Issue


Description

Aligned frontend registration validation rules with backend validation logic to prevent contradictory signup behavior.

Changes Made

  • Updated username validation regex in Signup.tsx
  • Updated password validation regex to match backend requirements
  • Improved frontend validation error messages for better user guidance
  • Ensured frontend and backend validation rules are fully consistent

Username Rules

  • Letters
  • Numbers
  • Underscores
  • No spaces

Password Rules

  • Minimum 8 characters
  • One uppercase letter
  • One lowercase letter
  • One number
  • One special character

How Has This Been Tested?

  • Tested valid and invalid usernames locally
  • Tested valid and invalid passwords locally
  • Verified frontend validation now matches backend validation behavior
  • Confirmed valid registrations submit successfully without backend validation conflicts

Screenshots (if applicable)

Screenshot 2026-05-26 083811 Screenshot 2026-05-26 083935

Type of Change

  • Bug fix
  • New feature
  • Code style update
  • Breaking change
  • Documentation update

Summary by CodeRabbit

  • Bug Fixes
    • Strengthened password validation requirements (minimum 8 characters enforced)
    • Updated username field validation to accept letters, numbers, and underscores with corresponding error message changes

Review Change Stack

@netlify
Copy link
Copy Markdown

netlify Bot commented May 26, 2026

Deploy Preview for github-spy ready!

Name Link
🔨 Latest commit e772265
🔍 Latest deploy log https://app.netlify.com/projects/github-spy/deploys/6a19c76cb046030008018111
😎 Deploy Preview https://deploy-preview-530--github-spy.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 26, 2026

Warning

Review limit reached

@mehul-m-prajapati, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 26 minutes and 18 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 14ffddd1-ed8b-42fb-95ff-bd95be542dd5

📥 Commits

Reviewing files that changed from the base of the PR and between 348ea60 and e772265.

📒 Files selected for processing (1)
  • src/pages/Signup/Signup.tsx
📝 Walkthrough

Walkthrough

Backend password validation tightened with explicit quantifier syntax. Frontend username input validation expanded to accept letters, digits, and underscores, while form submission validation retains the previous letters/spaces-only rule—creating an internal inconsistency. Multiple JSX className attributes reformatted across lines without logic changes.

Changes

Validation Alignment

Layer / File(s) Summary
Backend authentication schema updates
backend/validators/authValidator.js
Username field .trim() formatting adjusted; password regex tightened from +-based ending to explicit {8,}+ quantifier for minimum 8-character enforcement.
Frontend username validation in input handler
src/pages/Signup/Signup.tsx
handleChange method updated to allow letters, digits, and underscores instead of letters and spaces only; corresponding error message changed to match.
Frontend form submission validation and error messages
src/pages/Signup/Signup.tsx
handleSubmit error string blocks reformatted across multiple lines; username validation still uses prior letters/spaces-only regex and "Only letters are allowed" message, contradicting the updated handleChange behavior.
Frontend styling and layout formatting
src/pages/Signup/Signup.tsx
Page background container, card/header, and bottom gradient className template literals split across multiple lines for readability; no semantic class changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related issues

Possibly related PRs

  • GitMetricsLab/github_tracker#265: Both PRs modify username validation logic in src/pages/Signup/Signup.tsx, aligning frontend input handling with backend expectations.
  • GitMetricsLab/github_tracker#279: Both PRs update the Zod signupSchema in backend/validators/authValidator.js, extending the authentication schema constraints.

Suggested labels

level:intermediate, quality:clean, type:bug

Poem

🐰 A rabbit's hop through validation rules,
Where frontend and backend play different schools.
Username now dances with numbers and dashes—
But the form still rejects? Oh, such clashing!
Fix the contradiction, let users rejoice! 🌟

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR includes contradictions: username validation in handleChange uses the correct pattern, but handleSubmit still uses the old pattern; password validation regex in the backend appears malformed with invalid quantifier syntax. Fix the discrepancy in username validation between handleChange and handleSubmit to ensure consistency; clarify and correct the password regex syntax in authValidator.js to match the documented requirements.
Out of Scope Changes check ⚠️ Warning JSX className reformatting changes in Signup.tsx are unrelated to the core objective of aligning validation rules between frontend and backend. Remove the JSX className formatting changes and keep the PR focused solely on validation logic alignment; separate cosmetic changes into a different PR.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main objective of aligning frontend auth validation with backend validation.
Description check ✅ Passed The description follows the template, includes all required sections (related issue, description, testing, type of change), and provides sufficient detail about the changes made.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/pages/Signup/Signup.tsx (1)

56-58: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Password regex is still weaker than backend requirements in both validation paths.

Lines 56 and 77 only require letters+numbers and don’t enforce uppercase/lowercase/special-character presence, so frontend and backend can still disagree.

💡 Suggested fix (single source used in both checks)
+  const PASSWORD_REGEX =
+    /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]+$/;
...
-      } else if (!/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d@$!%*#?&]{8,}$/.test(value)) {
-        errorMessage = "Password must be 8+ characters with letters and numbers";
+      } else if (!PASSWORD_REGEX.test(value)) {
+        errorMessage =
+          "Password must be at least 8 characters and include uppercase, lowercase, number, and special character";
       }
...
-    const passwordError = !formData.password.trim()
-      ? "Password is required"
-      : !/^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d@$!%*#?&]{8,}$/.test(formData.password)
-        ? "Password must be 8+ characters with letters and numbers"
-        : "";
+    const passwordError = !formData.password.trim()
+      ? "Password is required"
+      : !PASSWORD_REGEX.test(formData.password)
+        ? "Password must be at least 8 characters and include uppercase, lowercase, number, and special character"
+        : "";

Also applies to: 75-79

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/pages/Signup/Signup.tsx` around lines 56 - 58, The password check in
Signup.tsx is weaker than backend rules; extract a single constant (e.g.,
PASSWORD_REGEX) and use it in both validation paths instead of the current
inline regex so frontend and backend agree; set the regex to require at least
one lowercase, one uppercase, one digit, one special character and minimum
length 8 (e.g. (?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*#?&]).{8,}), replace the
two inline tests with PASSWORD_REGEX.test(value) (or the equivalent function
like validatePassword) and update the errorMessage text to reflect the new
requirements.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@backend/validators/authValidator.js`:
- Line 21: The regex for signupSchema.password contains an invalid possessive
quantifier `{8,}+` which is a syntax error; update the pattern used in
signupSchema (the password regex) to remove the possessive plus and use a
standard quantifier such as `{8,}` (or rely on existing .min(8)/.max(100)
validations) so the regex becomes valid ECMAScript and signup validation can
load correctly. Ensure you edit the pattern in the signupSchema.password
definition where the regex is declared.

In `@src/pages/Signup/Signup.tsx`:
- Around line 65-69: The submit-time validation for username (variable
usernameError) uses a regex that allows only letters/spaces but must match the
live validation/backend rule; update the ternary branch that tests
formData.username to use a regex allowing letters, digits and underscores (e.g.
/^[A-Za-z0-9_]+$/) while keeping the initial trim check, so usernameError logic
aligns with the live validator and backend contract.

---

Outside diff comments:
In `@src/pages/Signup/Signup.tsx`:
- Around line 56-58: The password check in Signup.tsx is weaker than backend
rules; extract a single constant (e.g., PASSWORD_REGEX) and use it in both
validation paths instead of the current inline regex so frontend and backend
agree; set the regex to require at least one lowercase, one uppercase, one
digit, one special character and minimum length 8 (e.g.
(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*#?&]).{8,}), replace the two inline
tests with PASSWORD_REGEX.test(value) (or the equivalent function like
validatePassword) and update the errorMessage text to reflect the new
requirements.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 177bc73b-d714-4088-8c95-c1da07c42d4b

📥 Commits

Reviewing files that changed from the base of the PR and between 6c6bc3e and 348ea60.

📒 Files selected for processing (2)
  • backend/validators/authValidator.js
  • src/pages/Signup/Signup.tsx

.max(100, "Password must be at most 100 characters long")
.regex(
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]+$/,
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}+$/,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🌐 Web query:

Does JavaScript (ECMAScript regex) support possessive quantifiers like {8,}+? If not, what is the correct equivalent for enforcing length alongside .min(8) validation?

💡 Result:

No. JavaScript regular expressions (ECMAScript) do not support possessive quantifier syntax like {8,}+; attempting it results in a syntax error (e.g., “Nothing to Repeat”) because ECMAScript regex only recognizes greedy quantifiers ({8,}) and non-greedy ones ({8,}?), not possessive ones [1][2]. Correct equivalent (enforce minimum length / no .min(8)-style “backtracking control”): use a normal quantifier with a length anchor. - If you want “length at least 8” for the whole input: ^.{8,}$ (or with a specific character class, e.g. ^[A-Za-z0-9]{8,}$). - If you only need to match a substring of length ≥ 8 inside a larger string: .{8,}. Note: possessive quantifiers are about preventing backtracking for performance/engine control, not about adding a “minimum length” constraint. For length validation in regex, use quantifiers {n,} (or {n,m}) and anchors like ^ and $ as shown above [2][3].

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Show the region around the targeted line
nl -ba backend/validators/authValidator.js | sed -n '1,120p'

# Focus on password schema/regex area
rg -n "password|regex|signupSchema|min\\(8\\)" backend/validators/authValidator.js || true

Repository: GitMetricsLab/github_tracker

Length of output: 115


🏁 Script executed:

#!/bin/bash
set -euo pipefail

FILE="backend/validators/authValidator.js"

# Print a small window around the cited line (21) using cat -n
if [ -f "$FILE" ]; then
  cat -n "$FILE" | sed -n '1,80p'
else
  echo "Missing file: $FILE"
  exit 1
fi

# Narrow search for password/regex/min(8)
rg -n "password|signupSchema|regex|min\\(8\\)|\\{8,\\}\\+" "$FILE" || true

Repository: GitMetricsLab/github_tracker

Length of output: 1824


Fix invalid password regex quantifier ({8,}+)
backend/validators/authValidator.js contains {8,}+ in signupSchema.password’s regex; ECMAScript regex doesn’t support possessive quantifiers like this, so it’s a regex syntax error that can prevent the module from loading (breaking signup validation). Replace {8,}+ with a valid quantifier such as {8,} (length is already enforced via .min(8) / .max(100)).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@backend/validators/authValidator.js` at line 21, The regex for
signupSchema.password contains an invalid possessive quantifier `{8,}+` which is
a syntax error; update the pattern used in signupSchema (the password regex) to
remove the possessive plus and use a standard quantifier such as `{8,}` (or rely
on existing .min(8)/.max(100) validations) so the regex becomes valid ECMAScript
and signup validation can load correctly. Ensure you edit the pattern in the
signupSchema.password definition where the regex is declared.

Comment on lines 65 to +69
const usernameError = !formData.username.trim()
? "Username is required"
: !/^[A-Za-z\s]+$/.test(formData.username)
? "Only letters are allowed"
: "";
? "Only letters are allowed"
: "";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Submit-time username rule still contradicts live validation and backend contract.

Line 67 still enforces letters/spaces only, while Line 42 allows letters, numbers, and underscores. This reintroduces frontend inconsistency.

💡 Suggested fix
-    const usernameError = !formData.username.trim()
-      ? "Username is required"
-      : !/^[A-Za-z\s]+$/.test(formData.username)
-        ? "Only letters are allowed"
-        : "";
+    const usernameError = !formData.username.trim()
+      ? "Username is required"
+      : !/^[a-zA-Z0-9_]+$/.test(formData.username)
+        ? "Username can contain only letters, numbers, and underscores"
+        : "";
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const usernameError = !formData.username.trim()
? "Username is required"
: !/^[A-Za-z\s]+$/.test(formData.username)
? "Only letters are allowed"
: "";
? "Only letters are allowed"
: "";
const usernameError = !formData.username.trim()
? "Username is required"
: !/^[a-zA-Z0-9_]+$/.test(formData.username)
? "Username can contain only letters, numbers, and underscores"
: "";
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/pages/Signup/Signup.tsx` around lines 65 - 69, The submit-time validation
for username (variable usernameError) uses a regex that allows only
letters/spaces but must match the live validation/backend rule; update the
ternary branch that tests formData.username to use a regex allowing letters,
digits and underscores (e.g. /^[A-Za-z0-9_]+$/) while keeping the initial trim
check, so usernameError logic aligns with the live validator and backend
contract.

@mehul-m-prajapati mehul-m-prajapati merged commit 1bd3621 into GitMetricsLab:main May 29, 2026
4 of 6 checks passed
@github-actions
Copy link
Copy Markdown

🎉🎉 Thank you for your contribution! Your PR #530 has been merged! 🎉🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 Bug Report: User Registration Broken — Frontend and Backend Validation Rules Contradict Each Other

2 participants