Issue: Centralize authentication logic using middleware and add login redirect support
Description:
Endpoints currently perform authentication checks manually, e.g.:
This duplicates logic across routes and makes maintenance error-prone.
Recommendation:
- Implement a shared authentication middleware that validates the session and either continues or redirects to the login page.
- Add a
redirect query parameter to the login page so users are returned to their original destination after successful authentication.
Benefits:
- Reduces code duplication and improves consistency
- Simplifies adding new protected routes
- Provides smoother user experience with post-login redirects