-
Notifications
You must be signed in to change notification settings - Fork 0
Improve auth flow #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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
lib/constants.gofor more precise error handling in authentication flows, replacing generic error messages with specific ones likeErrUserAlreadyExists,ErrUsernameTaken, and others.AuthServiceto consistently use a logger instance, replacing directlogcalls and ensuring all handler/service instantiations pass the logger for improved observability. [1] [2] [3] [4] [5] [6] [7]auth_service.goto 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]Frontend Improvements
use-auth-context.tsxto only redirect users to the login page when they attempt to access protected routes, improving user experience. [1] [2]LoginFormandRegisterFormcomponents to accept anisLoadingprop and correctly display loading states when authentication requests are pending, preventing duplicate submissions. [1] [2] [3] [4]These changes collectively increase the reliability, maintainability, and usability of the authentication system.