Skip to content

fix(auth): add login validation, error handling, and fix ProtectedRoute bypass #63#126

Merged
abhishek-nexgen-dev merged 3 commits into
NexGenStudioDev:masterfrom
rajesh-puripanda:fix/login-authentication
Jun 1, 2026
Merged

fix(auth): add login validation, error handling, and fix ProtectedRoute bypass #63#126
abhishek-nexgen-dev merged 3 commits into
NexGenStudioDev:masterfrom
rajesh-puripanda:fix/login-authentication

Conversation

@rajesh-puripanda
Copy link
Copy Markdown
Contributor

Problem

The login page (/) performed no authentication whatsoever:

  • Empty fields were accepted with no validation error
  • No API call, no token check, no session — nothing
  • ProtectedRoute used a hardcoded mock user (dashboardData.user with role "Admin"), making role-based access control completely meaningless
  • Anyone could access the full dashboard without credentials

Root Cause

  1. LoginPage had no client-side validation and no error feedback in the UI
  2. ProtectedRoute accepted a user prop that was hardcoded to dashboardData.user in OrgRoute.tsx — the auth store was never consulted
  3. AuthStore had the token field commented out and never persisted it

Changes

File Change
src/features/Auth/v1/Pages/LoginPage.tsx Added validateFields() (email format regex + empty field checks), inline field errors, server error banner, loading/disabled button state, member role redirect
src/features/Auth/v1/Types/Auth.type.ts Uncommented token in AuthState, updated setAuthData signature
src/features/Auth/v1/Store/Auth.Store.ts setAuthData now accepts and stores token; clearAuthData clears it
src/features/Auth/v1/hooks/useAuth.ts Passes response.token to setAuthData on successful login
src/routes/ProtectedRoute.tsx Reads user from useAuthStore instead of accepting a prop (core security fix)
src/routes/OrgRoute.tsx Removed hardcoded dashboardData.user prop and unused mock import

Security Impact

  • Before: Anyone could navigate directly to /org/dashboard with zero authentication
  • After: ProtectedRoute reads from the zustand auth store; unauthenticated users are redirected to /; wrong roles go to /unauthorized
  • Client-side validation prevents empty form submissions
  • Server errors are surfaced in the UI instead of silently swallowed

Testing

  • tsc --noEmit passes with zero errors
  • Empty form submit shows validation errors
  • Invalid credentials show server error banner
  • Button shows loading state during API call
  • Authenticated org users reach dashboard; unauthenticated users are redirected to login

Closes #63

…te bypass

- Add client-side validation (empty fields, email format) to LoginPage
- Show inline field errors and server error banner in login UI
- Disable Sign In button and show loading state during API call
- Store JWT token in AuthStore on successful login
- Fix ProtectedRoute to read user from auth store instead of hardcoded mock
- Remove hardcoded dashboardData.user prop from OrgRoute
- Add member role redirect to /member/dashboard

Closes NexGenStudioDev#63
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces client-side validation, server error handling, and a loading state to the login page, while also integrating authentication token management into the Zustand store. Additionally, ProtectedRoute has been refactored to retrieve the authenticated user directly from the store rather than receiving it as a prop. Feedback on these changes suggests wrapping the new validateFields function in useCallback and adding it to the dependency array of handleLogin to ensure correct hook memoization.

Comment thread src/features/Auth/v1/Pages/LoginPage.tsx Outdated
Comment thread src/features/Auth/v1/Pages/LoginPage.tsx Outdated
rajesh-puripanda and others added 2 commits May 31, 2026 02:04
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@abhishek-nexgen-dev abhishek-nexgen-dev merged commit 3e78b77 into NexGenStudioDev:master Jun 1, 2026
2 checks passed
@rajesh-puripanda
Copy link
Copy Markdown
Contributor Author

Hi @abhishek-nexgen-dev,

Thank you for merging the fix for the authentication bypass issue (#63 / #126).

As this work was completed as part of GSSoC, could you please help add the appropriate GSSoC label to the PR? Please let me know if there is anything else needed from my side to ensure the contribution is correctly tracked.

Thanks again!

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] Login page has no authentication — Sign In bypasses credentials entirely

2 participants