Auth / Author Flow Hardening and Client Separation #1
Reference in New Issue
Block a user
No description provided.
Delete Branch "jwt"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Merge Request: Auth / Author Flow Hardening and Client Separation
Summary
This change set improves the authentication–author lifecycle by clearly separating Auth and Blog API clients, ensuring an Author is created at registration time, and preventing user-controlled mutation of immutable identity fields in the UI.
The result is a cleaner contract between services, fewer edge cases around missing authors, and more predictable client behavior.
Key Changes
1. Username Made Read-Only in Profile UI
usernamefield inProfile.tsx2. Dedicated Auth vs Blog API Clients
auth)api401handling and token invalidation logicWhy:
Auth and Blog are separate concerns and potentially separate services. Explicit clients reduce coupling and eliminate ambiguous routing.
3. Registration Flow Now Creates Author Automatically
register()now:This guarantees:
4. Correct Endpoint Usage for “Current User”
/auth/meis now correctly called via the Auth client/authors/mereplaces ID-based lookup for the current author5. Centralized Token & Auth Error Handling
401consistently6. Environment Configuration Updated
VITE_AUTH_BASE_URLto support separate Auth service routingImpact
Notes / Follow-ups
401can be wired later via an event bus or global handlerRisk Level: Low
Behavioral Change: Yes (author auto-created on registration)
Backward Compatibility: Requires Auth + Blog services to be reachable separately
## Summary Refactored the authentication flow to correctly separate traffic between the Auth service and Blog service. Added post-registration author creation and switched all `/auth/*` calls to the dedicated `auth` Axios client. ## Changes ### AuthProvider - Replaced `api.post('/auth/register')` with `auth.post('/register')` - Replaced `api.post('/auth/login')` with `auth.post('/login')` - Added automatic author creation after user registration (`POST /authors`) - Switched user identity lookup from `api.get('/auth/me')` to `auth.get('/me')` - Replaced `/authors/{id}` lookup with `/authors/me` - Updated imports to use `{ api, auth }` ### Axios Client Layer - Introduced a new `auth` Axios instance using `VITE_AUTH_BASE_URL` - Added shared token attachment and 401 handling logic - Applied interceptors to both `auth` and `api` clients - Removed inline auth logic from `api.ts` ### Types - Added `VITE_AUTH_BASE_URL` to `vite-env.d.ts` ## Impact - Correctly routes authentication traffic to the Auth microservice - Ensures an Author document is created automatically after registration - Simplifies identity loading via `/authors/me` - Improves token handling consistency across both servicesjwtto Auth / Author Flow Hardening and Client Separation