Skip to content

Conversation

@MonkyMars
Copy link
Owner

This pull request introduces several improvements and refactors to the authentication flow in both the backend and frontend. The main changes include better error handling with custom error types, consistent logger usage throughout authentication services, improved feedback and redirection for authentication failures, and UI enhancements for loading states. These updates aim to make the authentication process more robust, maintainable, and user-friendly.

Backend Improvements

  • Added custom error types to lib/constants.go for more precise error handling in authentication flows, replacing generic error messages with specific ones like ErrUserAlreadyExists, ErrUsernameTaken, and others.
  • Refactored AuthService to consistently use a logger instance, replacing direct log calls and ensuring all handler/service instantiations pass the logger for improved observability. [1] [2] [3] [4] [5] [6] [7]
  • Updated error handling in auth_service.go to use the new custom error types, improved logging for failures, and standardized error responses in registration and token refresh flows. [1] [2] [3] [4] [5]
  • Changed the behavior in authentication middleware to avoid returning internal Redis errors to clients, increasing security and user experience.

Frontend Improvements

  • Enhanced protected route handling in use-auth-context.tsx to only redirect users to the login page when they attempt to access protected routes, improving user experience. [1] [2]
  • Updated LoginForm and RegisterForm components to accept an isLoading prop and correctly display loading states when authentication requests are pending, preventing duplicate submissions. [1] [2] [3] [4]
  • Improved logout behavior to always redirect users to the login page after logging out, ensuring session termination is clear.

These changes collectively increase the reliability, maintainability, and usability of the authentication system.

@MonkyMars MonkyMars self-assigned this Sep 27, 2025
Copilot AI review requested due to automatic review settings September 27, 2025 09:49
@MonkyMars MonkyMars added documentation Improvements or additions to documentation enhancement New feature or request react/ui Updates the react UI go/fiber Updates the go fiber server labels Sep 27, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves the authentication flow by implementing better error handling with custom error types, consistent logger usage, and enhanced user experience with improved loading states and navigation logic.

  • Added custom error types to replace generic error messages in authentication services
  • Refactored AuthService to consistently use logger instances throughout the codebase
  • Enhanced frontend authentication flow with better loading state handling and conditional redirects

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
apps/server/lib/constants.go Added custom error constants for authentication operations
apps/server/services/auth_service.go Integrated logger and replaced generic errors with custom error types
apps/server/api/internal/auth.go Updated service instantiation to include logger parameter
apps/server/api/middleware/auth.go Added logger to AuthService instantiation and improved error handling
apps/ui/app/routes/login.tsx Simplified loading logic and passed loading state to form component
apps/ui/app/routes/register.tsx Simplified loading logic and passed loading state to form component
apps/ui/app/components/auth/login-form.tsx Added isLoading prop for better loading state management
apps/ui/app/components/auth/register-form.tsx Added isLoading prop for better loading state management
apps/ui/app/hooks/use-auth-context.tsx Enhanced protected route detection to prevent unnecessary redirects
apps/ui/app/hooks/use-auth.ts Added automatic redirect to login page after logout
apps/ui/app/lib/api-client.ts Improved auth failure handling to avoid triggering on expected 401s
apps/ui/app/root.tsx Added suppressHydrationWarning attribute

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@MonkyMars MonkyMars merged commit 91c3707 into main Sep 27, 2025
3 checks passed
@MonkyMars MonkyMars deleted the feature/auth-flow branch September 27, 2025 20:18
Copilot AI mentioned this pull request Sep 29, 2025
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request go/fiber Updates the go fiber server react/ui Updates the react UI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant