fix(auth): add login validation, error handling, and fix ProtectedRoute bypass #63#126
Conversation
…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
There was a problem hiding this comment.
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.
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>
|
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! |
Problem
The login page (/) performed no authentication whatsoever:
ProtectedRouteused a hardcoded mock user (dashboardData.userwith role"Admin"), making role-based access control completely meaninglessRoot Cause
userprop that was hardcoded todashboardData.userinOrgRoute.tsx— the auth store was never consultedtokenfield commented out and never persisted itChanges
src/features/Auth/v1/Pages/LoginPage.tsxvalidateFields()(email format regex + empty field checks), inline field errors, server error banner, loading/disabled button state, member role redirectsrc/features/Auth/v1/Types/Auth.type.tstokeninAuthState, updatedsetAuthDatasignaturesrc/features/Auth/v1/Store/Auth.Store.tssetAuthDatanow accepts and storestoken;clearAuthDataclears itsrc/features/Auth/v1/hooks/useAuth.tsresponse.tokentosetAuthDataon successful loginsrc/routes/ProtectedRoute.tsxuserfromuseAuthStoreinstead of accepting a prop (core security fix)src/routes/OrgRoute.tsxdashboardData.userprop and unused mock importSecurity Impact
/org/dashboardwith zero authenticationProtectedRoutereads from the zustand auth store; unauthenticated users are redirected to/; wrong roles go to/unauthorizedTesting
tsc --noEmitpasses with zero errorsCloses #63