Skip to content

Enhance Auth API with Refresh Endpoint and Investigate Middleware Integration #685

Description

@Skoivumaki

✨ Enhancement Description

Provide a brief description of the enhancement or improvement being suggested:

  • What is it?: This issue covers two related tasks:

    1. API Enhancement: Add a new function to authApi.ts that calls the backend's token refresh endpoint. This function will not be implemented in the application's logic yet, but will be added to the API layer for future use.
    2. Middleware Investigation: Investigate the feasibility of integrating this refresh logic directly into authMiddleware.ts. The goal is to have the middleware automatically handle token refreshing and subsequently update both the Redux store and localStorage with the new authentication data.
  • Why improve it?: Only way to fetch fresh auth data is via login currently.


🌟 Benefits of the Enhancement

Explain how this enhancement will improve the project or user experience:

  • Project Impact:
    • Maintainability: Centralizing the refresh logic in authMiddleware.ts (if feasible) avoids duplicating logic across the application and makes the authentication flow easier to manage and debug.
    • Foundation for Future Features: Having a tested refreshAuth function in authApi.ts is a prerequisite for any future feature that requires manual or automated session extension.

🛠️ Proposed Implementation

Outline how the enhancement could be implemented, including any technical considerations:

  • Technical Details:

    • The new endpoint is documented in the Swagger UI: https://devapi.altzone.fi/swagger#/Auth/AuthController. (Note: The documentation is behind authentication, ask if you don't have them).
    • The implementation will require a way to test the new API function, as it won't be integrated into the main application flow yet.
    • The middleware investigation will need to consider how to handle asynchronous operations, access the Redux store, and interact with localStorage from within the middleware.
  • Implementation Plan:

    1. Add refreshAuth function to authApi.ts:
      • Implement refresh endpoint to authApi.ts.
    2. Create a Test Mechanism:
      • Create a simple, non-production page (e.g., /admin) with a button.
      • The button's onClick handler will call the new refreshAuth function from authApi.ts.
      • Check localStorage for updates and if possible render the redux store on page.
    3. Investigate authMiddleware.ts Integration:
      • Analyze the current authMiddleware.ts to understand its structure.
      • On a successful refresh, dispatch a Redux action to update the store.
      • Simultaneously, update the localStorage with the new token data to ensure persistence across sessions.
      • Document the findings, including potential challenges, proposed code structure, and any required changes to the Redux authSlice.

📎 Additional Information

Include any additional context, examples, or resources that could help in understanding or implementing the enhancement:

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementFor improvements to existing features

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions